Hi,

I´m binding an array of my own class to a datagrid.

The problem I have is that I don´t know where I have to code the order of
the columns (the public properties of my class). Datagrid sort them in a
"weird" algorithm cause it does´t sort alphabetically or by ocurrence on the
class.

How can I tell the datagrid how to sort this columns (properties).

Re: Datagrid: Binding to custom collection by pdavis68

pdavis68
Wed Jun 23 12:49:34 CDT 2004

I believe the default order of the columns is the result of the order that
reflection returns the public properties.

To specify the order, you can create DataGridColumnStyle derived classes
(DataGridBoolColumn and DataGridTextBoxColumn) for each column and add them
to a DataGridTableStyle's GridColumnStyles collection. Then add that table
style to the grid.

Here's an example from the MSDN:

private void AddGridStyle()
{
DataGridTableStyle myGridStyle = new DataGridTableStyle();
myGridStyle.MappingName = "NamesTable";

DataGridTextBoxColumn nameColumnStyle =
new DataGridTextBoxColumn();
nameColumnStyle.MappingName = "Name";
nameColumnStyle.HeaderText= "Name";
myGridStyle.GridColumnStyles.Add(nameColumnStyle);

DataGridTimePickerColumn timePickerColumnStyle =
new DataGridTimePickerColumn();
timePickerColumnStyle.MappingName = "Date";
timePickerColumnStyle.HeaderText = "Date";
timePickerColumnStyle.Width = 100;
myGridStyle.GridColumnStyles.Add(timePickerColumnStyle);

grid.TableStyles.Add(myGridStyle);
}

"Carlos Campos" <carlos@(NoSpam)costarricense.cr> wrote in message
news:%23scWjnTWEHA.1760@TK2MSFTNGP10.phx.gbl...
> Hi,
>
> I´m binding an array of my own class to a datagrid.
>
> The problem I have is that I don´t know where I have to code the order of
> the columns (the public properties of my class). Datagrid sort them in a
> "weird" algorithm cause it does´t sort alphabetically or by ocurrence on
the
> class.
>
> How can I tell the datagrid how to sort this columns (properties).
>
>



Re: Datagrid: Binding to custom collection by Carlos

Carlos
Thu Jun 24 09:43:31 CDT 2004

I tried to use your code, but it didn´t work, maybe cause I don´t know what
I have to set in the MappingName. Checking Help the Mapping Name must
contain the DataTable Name, but I´m using an array of custom classes with
??? name, so I think the Datagrid is using the default style.

Any idea?

<pdavis68@hotmail.com> wrote in message
news:ucCdndBrJqsyX0TdRVn-hQ@giganews.com...
> I believe the default order of the columns is the result of the order that
> reflection returns the public properties.
>
> To specify the order, you can create DataGridColumnStyle derived classes
> (DataGridBoolColumn and DataGridTextBoxColumn) for each column and add
them
> to a DataGridTableStyle's GridColumnStyles collection. Then add that table
> style to the grid.
>
> Here's an example from the MSDN:
>
> private void AddGridStyle()
> {
> DataGridTableStyle myGridStyle = new DataGridTableStyle();
> myGridStyle.MappingName = "NamesTable";
>
> DataGridTextBoxColumn nameColumnStyle =
> new DataGridTextBoxColumn();
> nameColumnStyle.MappingName = "Name";
> nameColumnStyle.HeaderText= "Name";
> myGridStyle.GridColumnStyles.Add(nameColumnStyle);
>
> DataGridTimePickerColumn timePickerColumnStyle =
> new DataGridTimePickerColumn();
> timePickerColumnStyle.MappingName = "Date";
> timePickerColumnStyle.HeaderText = "Date";
> timePickerColumnStyle.Width = 100;
> myGridStyle.GridColumnStyles.Add(timePickerColumnStyle);
>
> grid.TableStyles.Add(myGridStyle);
> }
>
> "Carlos Campos" <carlos@(NoSpam)costarricense.cr> wrote in message
> news:%23scWjnTWEHA.1760@TK2MSFTNGP10.phx.gbl...
> > Hi,
> >
> > I´m binding an array of my own class to a datagrid.
> >
> > The problem I have is that I don´t know where I have to code the order
of
> > the columns (the public properties of my class). Datagrid sort them in a
> > "weird" algorithm cause it does´t sort alphabetically or by ocurrence on
> the
> > class.
> >
> > How can I tell the datagrid how to sort this columns (properties).
> >
> >
>
>



Re: Datagrid: Binding to custom collection by pdavis68

pdavis68
Thu Jun 24 11:04:39 CDT 2004

Carlos,

As I said in my e-mail to you, the MappingName should have the name of
the properties of the objects in your collection that you want displayed.

Pete

"Carlos Campos" <carlos@(NoSpam)costarricense.cr> wrote in message
news:ug9oWnfWEHA.2844@TK2MSFTNGP11.phx.gbl...
> I tried to use your code, but it didn´t work, maybe cause I don´t know
what
> I have to set in the MappingName. Checking Help the Mapping Name must
> contain the DataTable Name, but I´m using an array of custom classes with
> ??? name, so I think the Datagrid is using the default style.
>
> Any idea?
>
> <pdavis68@hotmail.com> wrote in message
> news:ucCdndBrJqsyX0TdRVn-hQ@giganews.com...
> > I believe the default order of the columns is the result of the order
that
> > reflection returns the public properties.
> >
> > To specify the order, you can create DataGridColumnStyle derived classes
> > (DataGridBoolColumn and DataGridTextBoxColumn) for each column and add
> them
> > to a DataGridTableStyle's GridColumnStyles collection. Then add that
table
> > style to the grid.
> >
> > Here's an example from the MSDN:
> >
> > private void AddGridStyle()
> > {
> > DataGridTableStyle myGridStyle = new DataGridTableStyle();
> > myGridStyle.MappingName = "NamesTable";
> >
> > DataGridTextBoxColumn nameColumnStyle =
> > new DataGridTextBoxColumn();
> > nameColumnStyle.MappingName = "Name";
> > nameColumnStyle.HeaderText= "Name";
> > myGridStyle.GridColumnStyles.Add(nameColumnStyle);
> >
> > DataGridTimePickerColumn timePickerColumnStyle =
> > new DataGridTimePickerColumn();
> > timePickerColumnStyle.MappingName = "Date";
> > timePickerColumnStyle.HeaderText = "Date";
> > timePickerColumnStyle.Width = 100;
> > myGridStyle.GridColumnStyles.Add(timePickerColumnStyle);
> >
> > grid.TableStyles.Add(myGridStyle);
> > }
> >
> > "Carlos Campos" <carlos@(NoSpam)costarricense.cr> wrote in message
> > news:%23scWjnTWEHA.1760@TK2MSFTNGP10.phx.gbl...
> > > Hi,
> > >
> > > I´m binding an array of my own class to a datagrid.
> > >
> > > The problem I have is that I don´t know where I have to code the order
> of
> > > the columns (the public properties of my class). Datagrid sort them in
a
> > > "weird" algorithm cause it does´t sort alphabetically or by ocurrence
on
> > the
> > > class.
> > >
> > > How can I tell the datagrid how to sort this columns (properties).
> > >
> > >
> >
> >
>
>