Problem with DataGrid and an array

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.
 
M

Michael

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top