Infragistics的Winform控件UltraGrid不支持AutoGenerateColumns

UltraGrid(UltraWinGrid)不支持AutoGenerateColumns属性。本文介绍如何通过隐藏属性而非移除来控制列显示,并提供多种实现方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

      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) 编程手记

 

WinForms 应用程序中,数据列表控件用于显示和操作结构化数据。以下是一些常用的控件推荐,它们能够满足不同的功能需求和用户体验要求。 ### DataGridView 控件 `DataGridView` 是 WinForms 自带的核心数据列表控件,支持显示、编辑、排序和筛选等功能。它提供了高度的可定制性,允许开发者根据需求调整列类型、样式和数据绑定方式。对于大多数数据展示场景,`DataGridView` 是首选控件[^3]。 ### ListBox 控件 `ListBox` 用于显示简单的数据列表,支持单选或多选模式。它适合不需要复杂交互的小型数据集展示。通过数据绑定,`ListBox` 可以快速与数据源同步显示内容[^2]。 ### ComboBox 控件 虽然 `ComboBox` 主要用于选择操作,但它也可以作为轻量级的数据列表控件使用。它支持下拉列表形式的数据展示,适合空间有限的场景[^2]。 ### ListView 控件 `ListView` 提供了多种视图模式(如图标、列表、详细信息等),适用于需要灵活展示数据的应用程序。它支持排序、分组和自定义绘制功能,适合需要个性化设计的场景[^3]。 ### 第三方控件推荐 对于需要更高级功能的应用程序,可以考虑使用第三方控件库,例如: - **DevExpress GridControl**:提供丰富的功能,如分组、过滤、排序以及支持多种数据源绑定[^3]。 - **Telerik UI for WinForms**:包含强大的数据列表控件,支持数据虚拟化、高级样式和交互式功能。 - **Infragistics WinGrid**:适用于复杂数据展示,支持分层数据绑定和高度定制的界面设计。 ### 示例代码 以下是一个使用 `DataGridView` 的简单示例: ```csharp using System; using System.Windows.Forms; namespace DataGridViewExample { public partial class MainForm : Form { public MainForm() { InitializeComponent(); // 创建 DataGridView 控件 DataGridView dataGridView = new DataGridView { Dock = DockStyle.Fill, AutoGenerateColumns = true }; // 添加控件到窗体 this.Controls.Add(dataGridView); // 绑定数据源 var dataSource = new[] { new { ID = 1, Name = "Alice", Age = 25 }, new { ID = 2, Name = "Bob", Age = 30 }, new { ID = 3, Name = "Charlie", Age = 28 } }; dataGridView.DataSource = dataSource; } } } ``` ###
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值