如何对DataGrid中的列(而不是行)进行排序? [英] How do I sort the columns (not rows) in a DataGrid?

查看:97
本文介绍了如何对DataGrid中的列(而不是行)进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows窗体应用程序,其中我有一个DataGrid控件。我有一个

自定义类,它暴露了几个属性,我已经将这个

类或其集合,DataGrid的DataSource。 DataGrid的这个简洁的

功能允许属性显示在这个类的

集合中。


现在,如何我是否订购了这些列(不要与行混淆,这是由集合管理的
)?有没有一个简单的过程来执行此操作,而

仍然使用我的简单类而不是诉诸于ADO.NET或XML?我会

不想转移到ADO.NET或XML,但如果这是我唯一的选择,我想知道




Jon

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

推荐答案

我认为你必须设置自己的DataGridTableStyle:


DataGrid.DataGridTableStyle.GridColumnStyles.Clear(); //删除所有列

DataGrid.DataGridTableStyle.GridColumnStyles.AddRa nge(new

DataGrisColumnStyle [] {....}); //设置要显示的列以及

他们的订单


并按照您想要的顺序添加列


Jon Davis < jo*@REMOVE.ME.PLEASE.jondavis.net> schrieb im Newsbeitrag

新闻:%2 **************** @ TK2MSFTNGP10.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...
我有一个Windows窗体应用程序,其中我有一个DataGrid控件。我有一个
自定义类,它暴露了几个属性,我已经创建了这个类或者它的集合,DataGrid的DataSource。 DataGrid的这个简洁的功能允许属性显示在这个类的集合中。

现在,我如何订购列(不要与列混淆)行,
由集合管理)?有没有一个简单的过程来执行此操作,而
仍然使用我的简单类而不是诉诸于ADO.NET或XML?我宁愿不转向ADO.NET或XML,但如果这是我唯一的选择,我想要
来了解。

Jon
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



谢谢!


"ZürcherSee'" 3水溶液**** @ cannabismail.com>在消息中写道

新闻:ud ************** @ TK2MSFTNGP11.phx.gbl ...
Thanks!

"Zürcher See" <aq****@cannabismail.com> wrote in message
news:ud**************@TK2MSFTNGP11.phx.gbl...
我认为你必须设置自己的DataGridTableStyle:

DataGrid.DataGridTableStyle.GridColumnStyles.Clear(); //删除所有
列DataGrid.DataGridTableStyle.GridColumnStyles.AddRa nge(new
DataGrisColumnStyle [] {....}); //设置要显示的列以及他们的订单

并按照您想要的顺序添加列

Jon Davis < jo*@REMOVE.ME.PLEASE.jondavis.net> schrieb im Newsbeitrag
新闻:%2 **************** @ TK2MSFTNGP10.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...
我有一个Windows窗体应用程序其中我有一个DataGrid控件。我有一个
自定义类,它暴露了几个属性,我已经创建了这个类或者它的集合,DataGrid的DataSource。这个
整洁的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
?有没有一个简单的过程来执行此操作,而
仍然使用我的简单类而不是诉诸于ADO.NET或XML?我宁愿不转向ADO.NET或XML,但如果它是我唯一的选择我会
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

知道。

Jon
know.

Jon




谢谢!


"ZürcherSee'" 3水溶液**** @ cannabismail.com>在消息中写道

新闻:ud ************** @ TK2MSFTNGP11.phx.gbl ...
Thanks!

"Zürcher See" <aq****@cannabismail.com> wrote in message
news:ud**************@TK2MSFTNGP11.phx.gbl...
我认为你必须设置自己的DataGridTableStyle:

DataGrid.DataGridTableStyle.GridColumnStyles.Clear(); //删除所有
列DataGrid.DataGridTableStyle.GridColumnStyles.AddRa nge(new
DataGrisColumnStyle [] {....}); //设置要显示的列以及他们的订单

并按照您想要的顺序添加列

Jon Davis < jo*@REMOVE.ME.PLEASE.jondavis.net> schrieb im Newsbeitrag
新闻:%2 **************** @ TK2MSFTNGP10.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...
我有一个Windows窗体应用程序其中我有一个DataGrid控件。我有一个
自定义类,它暴露了几个属性,我已经创建了这个类或者它的集合,DataGrid的DataSource。这个
整洁的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
?有没有一个简单的过程来执行此操作,而
仍然使用我的简单类而不是诉诸于ADO.NET或XML?我宁愿不转向ADO.NET或XML,但如果它是我唯一的选择我会
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

知道。

Jon
know.

Jon




这篇关于如何对DataGrid中的列(而不是行)进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆