469,962 Members | 2,341 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,962 developers. It's quick & easy.

How do I sort the columns (not rows) in a DataGrid?

I have a Windows Forms app in which I have a DataGrid control. I have a
custom class that has several properties exposed, and I have made this
class, or a collection thereof, the DataSource of the DataGrid. This neat
feature of the DataGrid allows the properties to be displayed in a
Collection of this class.

Now, how do I order the columns (not to be confused with the rows, which is
managed by the collection)? Is there a simple process to do this, while
still using my simple class and not resorting to ADO.NET or XML? I would
prefer not to move to ADO.NET or XML, but if it's my only option I'd like to
know.

Jon
Nov 15 '05 #1
11 1219
I think you have to set your own DataGridTableStyle:

DataGrid.DataGridTableStyle.GridColumnStyles.Clear (); //Remove all Columns
DataGrid.DataGridTableStyle.GridColumnStyles.AddRa nge(new
DataGrisColumnStyle[]{ .... }); // Set the columns to display and also
their order

And add the columns in the order that you want

"Jon Davis" <jo*@REMOVE.ME.PLEASE.jondavis.net> schrieb im Newsbeitrag
news:%2****************@TK2MSFTNGP10.phx.gbl...
I have a Windows Forms app in which I have a DataGrid control. I have a
custom class that has several properties exposed, and I have made this
class, or a collection thereof, the DataSource of the DataGrid. This neat
feature of the DataGrid allows the properties to be displayed in a
Collection of this class.

Now, how do I order the columns (not to be confused with the rows, which is managed by the collection)? Is there a simple process to do this, while
still using my simple class and not resorting to ADO.NET or XML? I would
prefer not to move to ADO.NET or XML, but if it's my only option I'd like to know.

Jon

Nov 15 '05 #2
Thanks!

"Zürcher See" <aq****@cannabismail.com> wrote in message
news:ud**************@TK2MSFTNGP11.phx.gbl...
I think you have to set your own DataGridTableStyle:

DataGrid.DataGridTableStyle.GridColumnStyles.Clear (); //Remove all Columns DataGrid.DataGridTableStyle.GridColumnStyles.AddRa nge(new
DataGrisColumnStyle[]{ .... }); // Set the columns to display and also
their order

And add the columns in the order that you want

"Jon Davis" <jo*@REMOVE.ME.PLEASE.jondavis.net> schrieb im Newsbeitrag
news:%2****************@TK2MSFTNGP10.phx.gbl...
I have a Windows Forms app in which I have a DataGrid control. I have a
custom class that has several properties exposed, and I have made this
class, or a collection thereof, the DataSource of the DataGrid. This neat feature of the DataGrid allows the properties to be displayed in a
Collection of this class.

Now, how do I order the columns (not to be confused with the rows, which is
managed by the collection)? Is there a simple process to do this, while
still using my simple class and not resorting to ADO.NET or XML? I would
prefer not to move to ADO.NET or XML, but if it's my only option I'd

like to
know.

Jon


Nov 15 '05 #3
Thanks!

"Zürcher See" <aq****@cannabismail.com> wrote in message
news:ud**************@TK2MSFTNGP11.phx.gbl...
I think you have to set your own DataGridTableStyle:

DataGrid.DataGridTableStyle.GridColumnStyles.Clear (); //Remove all Columns DataGrid.DataGridTableStyle.GridColumnStyles.AddRa nge(new
DataGrisColumnStyle[]{ .... }); // Set the columns to display and also
their order

And add the columns in the order that you want

"Jon Davis" <jo*@REMOVE.ME.PLEASE.jondavis.net> schrieb im Newsbeitrag
news:%2****************@TK2MSFTNGP10.phx.gbl...
I have a Windows Forms app in which I have a DataGrid control. I have a
custom class that has several properties exposed, and I have made this
class, or a collection thereof, the DataSource of the DataGrid. This neat feature of the DataGrid allows the properties to be displayed in a
Collection of this class.

Now, how do I order the columns (not to be confused with the rows, which is
managed by the collection)? Is there a simple process to do this, while
still using my simple class and not resorting to ADO.NET or XML? I would
prefer not to move to ADO.NET or XML, but if it's my only option I'd

like to
know.

Jon


Nov 15 '05 #4
Unfortunately, there is no DataGridTableStyle property in the Windows Forms
DataGrid. There is a TableStyles property, but it is a collection. If I go
MyDataGrid.TableStyles[0].GridColumnStyles.AddRange(new
DataGridColumnStyle[] {.... I don't know what to put here, and
DataGridColumnStyle's constructor is not accessible.

Jon

"Jon Davis" <jo*@REMOVE.ME.PLEASE.jondavis.net> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Thanks!

"Zürcher See" <aq****@cannabismail.com> wrote in message
news:ud**************@TK2MSFTNGP11.phx.gbl...
I think you have to set your own DataGridTableStyle:

DataGrid.DataGridTableStyle.GridColumnStyles.Clear (); //Remove all

Columns
DataGrid.DataGridTableStyle.GridColumnStyles.AddRa nge(new
DataGrisColumnStyle[]{ .... }); // Set the columns to display and also
their order

And add the columns in the order that you want

"Jon Davis" <jo*@REMOVE.ME.PLEASE.jondavis.net> schrieb im Newsbeitrag
news:%2****************@TK2MSFTNGP10.phx.gbl...
I have a Windows Forms app in which I have a DataGrid control. I have a custom class that has several properties exposed, and I have made this
class, or a collection thereof, the DataSource of the DataGrid. This neat feature of the DataGrid allows the properties to be displayed in a
Collection of this class.

Now, how do I order the columns (not to be confused with the rows, which
is
managed by the collection)? Is there a simple process to do this,

while still using my simple class and not resorting to ADO.NET or XML? I would prefer not to move to ADO.NET or XML, but if it's my only option I'd

like
to
know.

Jon



Nov 15 '05 #5
Unfortunately, there is no DataGridTableStyle property in the Windows Forms
DataGrid. There is a TableStyles property, but it is a collection. If I go
MyDataGrid.TableStyles[0].GridColumnStyles.AddRange(new
DataGridColumnStyle[] {.... I don't know what to put here, and
DataGridColumnStyle's constructor is not accessible.

Jon

"Jon Davis" <jo*@REMOVE.ME.PLEASE.jondavis.net> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Thanks!

"Zürcher See" <aq****@cannabismail.com> wrote in message
news:ud**************@TK2MSFTNGP11.phx.gbl...
I think you have to set your own DataGridTableStyle:

DataGrid.DataGridTableStyle.GridColumnStyles.Clear (); //Remove all

Columns
DataGrid.DataGridTableStyle.GridColumnStyles.AddRa nge(new
DataGrisColumnStyle[]{ .... }); // Set the columns to display and also
their order

And add the columns in the order that you want

"Jon Davis" <jo*@REMOVE.ME.PLEASE.jondavis.net> schrieb im Newsbeitrag
news:%2****************@TK2MSFTNGP10.phx.gbl...
I have a Windows Forms app in which I have a DataGrid control. I have a custom class that has several properties exposed, and I have made this
class, or a collection thereof, the DataSource of the DataGrid. This neat feature of the DataGrid allows the properties to be displayed in a
Collection of this class.

Now, how do I order the columns (not to be confused with the rows, which
is
managed by the collection)? Is there a simple process to do this,

while still using my simple class and not resorting to ADO.NET or XML? I would prefer not to move to ADO.NET or XML, but if it's my only option I'd

like
to
know.

Jon



Nov 15 '05 #6
In fact, TableStyles[0] fails because there are none.

"Jon Davis" <jo*@REMOVE.ME.PLEASE.jondavis.net> wrote in message
news:u5**************@TK2MSFTNGP09.phx.gbl...
Unfortunately, there is no DataGridTableStyle property in the Windows Forms DataGrid. There is a TableStyles property, but it is a collection. If I go
MyDataGrid.TableStyles[0].GridColumnStyles.AddRange(new
DataGridColumnStyle[] {.... I don't know what to put here, and
DataGridColumnStyle's constructor is not accessible.

Jon

"Jon Davis" <jo*@REMOVE.ME.PLEASE.jondavis.net> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Thanks!

"Zürcher See" <aq****@cannabismail.com> wrote in message
news:ud**************@TK2MSFTNGP11.phx.gbl...
I think you have to set your own DataGridTableStyle:

DataGrid.DataGridTableStyle.GridColumnStyles.Clear (); //Remove all Columns
DataGrid.DataGridTableStyle.GridColumnStyles.AddRa nge(new
DataGrisColumnStyle[]{ .... }); // Set the columns to display and also their order

And add the columns in the order that you want

"Jon Davis" <jo*@REMOVE.ME.PLEASE.jondavis.net> schrieb im Newsbeitrag
news:%2****************@TK2MSFTNGP10.phx.gbl...
> I have a Windows Forms app in which I have a DataGrid control. I have a
> custom class that has several properties exposed, and I have made
this > class, or a collection thereof, the DataSource of the DataGrid. This

neat
> feature of the DataGrid allows the properties to be displayed in a
> Collection of this class.
>
> Now, how do I order the columns (not to be confused with the rows,

which is
> managed by the collection)? Is there a simple process to do this, while > still using my simple class and not resorting to ADO.NET or XML? I would > prefer not to move to ADO.NET or XML, but if it's my only option I'd

like
to
> know.
>
> Jon
>
>



Nov 15 '05 #7
In fact, TableStyles[0] fails because there are none.

"Jon Davis" <jo*@REMOVE.ME.PLEASE.jondavis.net> wrote in message
news:u5**************@TK2MSFTNGP09.phx.gbl...
Unfortunately, there is no DataGridTableStyle property in the Windows Forms DataGrid. There is a TableStyles property, but it is a collection. If I go
MyDataGrid.TableStyles[0].GridColumnStyles.AddRange(new
DataGridColumnStyle[] {.... I don't know what to put here, and
DataGridColumnStyle's constructor is not accessible.

Jon

"Jon Davis" <jo*@REMOVE.ME.PLEASE.jondavis.net> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Thanks!

"Zürcher See" <aq****@cannabismail.com> wrote in message
news:ud**************@TK2MSFTNGP11.phx.gbl...
I think you have to set your own DataGridTableStyle:

DataGrid.DataGridTableStyle.GridColumnStyles.Clear (); //Remove all Columns
DataGrid.DataGridTableStyle.GridColumnStyles.AddRa nge(new
DataGrisColumnStyle[]{ .... }); // Set the columns to display and also their order

And add the columns in the order that you want

"Jon Davis" <jo*@REMOVE.ME.PLEASE.jondavis.net> schrieb im Newsbeitrag
news:%2****************@TK2MSFTNGP10.phx.gbl...
> I have a Windows Forms app in which I have a DataGrid control. I have a
> custom class that has several properties exposed, and I have made
this > class, or a collection thereof, the DataSource of the DataGrid. This

neat
> feature of the DataGrid allows the properties to be displayed in a
> Collection of this class.
>
> Now, how do I order the columns (not to be confused with the rows,

which is
> managed by the collection)? Is there a simple process to do this, while > still using my simple class and not resorting to ADO.NET or XML? I would > prefer not to move to ADO.NET or XML, but if it's my only option I'd

like
to
> know.
>
> Jon
>
>



Nov 15 '05 #8
Found the answer here.

http://support.microsoft.com/default...;EN-US;Q317383

Jon
Nov 15 '05 #9
Found the answer here.

http://support.microsoft.com/default...;EN-US;Q317383

Jon
Nov 15 '05 #10
Found the answer here:

http://support.microsoft.com/default...b;EN-US;317550

Jon

"Jon Davis" <jo*@REMOVE.ME.PLEASE.jondavis.net> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I have a Windows Forms app in which I have a DataGrid control. I have a
custom class that has several properties exposed, and I have made this
class, or a collection thereof, the DataSource of the DataGrid. This neat
feature of the DataGrid allows the properties to be displayed in a
Collection of this class.

Now, how do I order the columns (not to be confused with the rows, which is managed by the collection)? Is there a simple process to do this, while
still using my simple class and not resorting to ADO.NET or XML? I would
prefer not to move to ADO.NET or XML, but if it's my only option I'd like to know.

Jon

Nov 15 '05 #11
Found the answer here:

http://support.microsoft.com/default...b;EN-US;317550

Jon

"Jon Davis" <jo*@REMOVE.ME.PLEASE.jondavis.net> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I have a Windows Forms app in which I have a DataGrid control. I have a
custom class that has several properties exposed, and I have made this
class, or a collection thereof, the DataSource of the DataGrid. This neat
feature of the DataGrid allows the properties to be displayed in a
Collection of this class.

Now, how do I order the columns (not to be confused with the rows, which is managed by the collection)? Is there a simple process to do this, while
still using my simple class and not resorting to ADO.NET or XML? I would
prefer not to move to ADO.NET or XML, but if it's my only option I'd like to know.

Jon

Nov 15 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by yer darn tootin | last post: by
4 posts views Thread by Joe | last post: by
reply views Thread by thomasp | last post: by
1 post views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.