Infragistics的Winform控件UltraGrid(UltraWinGrid)不支持像Webform中UltraWebGrid控件的类似AutoGenerateColumns属性。就是自动触发列的控制属性,标准的DataGridView都有这个属性。UltraGrid只能绑定数据集的所有属性,要想按需显示列,一种方法是直接改变数据集的属性,另一种就是把不想显示的列隐藏掉。
Infragistics论坛的讨论 http://community.infragistics.com/forums/t/4171.aspx。
Mike Saltzman: No, the grid will always create all of the columns that are exposed by the data source. You can hide column by using the Hidden property, but you cannot remove them from the grid.
I don't know of any plans to change this. This would be a huge change to the fundamental infrastructure of the grid.
Why is this a problem? What is the difference if the column is hidden or does not exist in the grid?
If, for some reason, you absolutely must remove the column from the grid, then there are a number of ways you could acheive this. One way would be to create a data source that only has the columns you need. You could copy your data table. Or you could use the UltraDataSource in on-demand mode to act as a sort of intermediary between the grid and the real data source.
If you are implementing your own data source, you could implement ITypedList.
Another option would be to use the UltraWinTree, which allows you to define the column sets yourself
Mike Saltzman Windows Forms Development Team Lead Infragistics, Inc.
如果想动态创建UltraGrid的列, 我采取的方法为在绑定UltraGrid数据前,动态创建UltraGrid的列,这样可以控制列的顺序和汉化标题,然后在UltraGrid的Layout事件中把不需要的列隐藏掉。
在NetAdvantage_WinForms_20102_VS2010版本中测试通过。现在手头没有测试代码。
相关:
Infragistics netadvantage UltraGrid (UltraWinGrid) 编程手记