Problem with DataGrid and an array

  • Thread starter Thread starter Michael
  • Start date Start date
M

Michael

Hi,

I'm binding an array to a DataGrid. I only want some of the array's data to
show up. So I used DataGridTableStyle and DataGridColumnStyle. But whatever
I tried, my DataGrid shows all of the array's data, and non of my custom
settings seems to be working at all. Are DataGridTableStyle and
DataGridColumnStyle only for DataTable?

My code looks somewhat like:
DataGridTableStyle ts1 = new DataGridTableStyle();
ts1.MappingName = null;
ts1.AlternatingBackColor = Color.LightGray;

// Column 1
DataGridColumnStyle col1 = new DataGridTextBoxColumn();
col1.MappingName = "Name";
col1.HeaderText = "Name header";
col1.Width = 200;
ts1.GridColumnStyles.Add(col1);

// Column 2
DataGridColumnStyle col2 = new DataGridTextBoxColumn();
col2.MappingName = "tel";
col2.HeaderText = "Tel header";
col2.Width = 500;
ts1.GridColumnStyles.Add(col2);

this.DocumentsGrid.TableStyles.Clear(); // probably not needed
this.DocumentsGrid.TableStyles.Add(ts1);

MyClass[] myArray = BusinessClass.GetItems();
this.myDataGrid.SetDataBinding(myArray, null);

Thanks.
 
Thanks Claes.


Claes Bergefall said:
According to MSDN you should set
ts1.MappingName = "MyClass[]"

/claes


Michael said:
Hi,

I'm binding an array to a DataGrid. I only want some of the array's data
to show up. So I used DataGridTableStyle and DataGridColumnStyle. But
whatever I tried, my DataGrid shows all of the array's data, and non of
my custom settings seems to be working at all. Are DataGridTableStyle and
DataGridColumnStyle only for DataTable?

My code looks somewhat like:
DataGridTableStyle ts1 = new DataGridTableStyle();
ts1.MappingName = null;
ts1.AlternatingBackColor = Color.LightGray;

// Column 1
DataGridColumnStyle col1 = new DataGridTextBoxColumn();
col1.MappingName = "Name";
col1.HeaderText = "Name header";
col1.Width = 200;
ts1.GridColumnStyles.Add(col1);

// Column 2
DataGridColumnStyle col2 = new DataGridTextBoxColumn();
col2.MappingName = "tel";
col2.HeaderText = "Tel header";
col2.Width = 500;
ts1.GridColumnStyles.Add(col2);

this.DocumentsGrid.TableStyles.Clear(); // probably not needed
this.DocumentsGrid.TableStyles.Add(ts1);

MyClass[] myArray = BusinessClass.GetItems();
this.myDataGrid.SetDataBinding(myArray, null);

Thanks.
 
Back
Top