如何控制自定义业务对象的 dataGridViewColumn 顺序?
创建一个自定义业务对象以滑入 dataGridView 会产生奇迹......除了我想不出一种编程方式来设置列顺序。
我是否必须再次手动手动添加它们才能获得更好的排序,或者是否有一些我可以使用的神秘隐藏属性?
Creating a custom business object to slide into a dataGridView works wonders... except I can't think of a programmatic way to set the column order.
Do I have to add them one by one by hand manually again just to get a nicer sort or is there some cryptic hidden attribute I can use?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
每个 dataGridViewColumn 作为 DisplayIndex 属性,可以随时应用,甚至可以与设置为 true 的 AutoGenerateColumns 一起使用。
Each dataGridViewColumn as a DisplayIndex Property which can be applied at any time and even works with AutoGenerateColumns set to true.
我假设您当前已将
AutoGenerateColumns
设置为true
。 我知道控制列顺序的唯一方法是将 AutoGenerateColumns 设置为 false,然后像您所说的那样手动添加列。编辑:
我只是模糊地记忆了另一种执行此操作的方法,并认为您可能需要查看
GridView
控件的ColumnsGenerator
属性它接受一个 IAutoFieldGenerator 对象。 该接口有一个名为GenerateFields'的方法,它接受一个
Control(
Grid)并返回一个
ICollection `(Fields)。I assume that you currently have
AutoGenerateColumns
set totrue
. The only way I know to control the order of the columns is to setAutoGenerateColumns
tofalse
and, like you said, manually add the columns.EDIT:
I just looked into a vague memory of another way of doing this and think that you may want to look into the
GridView
control'sColumnsGenerator
property which takes aIAutoFieldGenerator
object. This interface has one method calledGenerateFields' which takes a
Control(the
Grid) and returns an
ICollection ` (of Fields).