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.

Re: Problem with DataGrid and an array by Claes

Claes
Fri Oct 14 02:20:31 CDT 2005

According to MSDN you should set
ts1.MappingName = "MyClass[]"

/claes


"Michael" <nospam@nospam.com> wrote in message
news:u6AuvaF0FHA.2932@TK2MSFTNGP10.phx.gbl...
> 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.
>



Re: Problem with DataGrid and an array by Michael

Michael
Fri Oct 14 11:51:37 CDT 2005

Thanks Claes.


"Claes Bergefall" <claes.bergefall@online.nospam> wrote in message
news:et0Mp9I0FHA.3180@TK2MSFTNGP14.phx.gbl...
> According to MSDN you should set
> ts1.MappingName = "MyClass[]"
>
> /claes
>
>
> "Michael" <nospam@nospam.com> wrote in message
> news:u6AuvaF0FHA.2932@TK2MSFTNGP10.phx.gbl...
>> 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.
>>
>
>