【问题标题】:Simple alternative for DataGridView which supports enumerations支持枚举的 DataGridView 的简单替代方案
【发布时间】:2011-04-20 10:12:14
【问题描述】:

我需要像 DataGridView 这样的东西。它应该能够绑定到以下对象的集合:

class Register
{
   TypeEnum Type{get;set;}
   string Name{get;set;}
}

它应该显示这个集合并允许编辑它们的属性:从组合框中选择所需的枚举值并在文本框中输入名称。此外,应该支持添加新对象和删除现有对象。

DataGridView 不适合,因为它不支持枚举。 如何在不进行过多手动编码的情况下实现此功能?

编辑:我尝试为此目的使用 DataGridView,但这很糟糕。如果不使用容易出错的处理程序创建其他按钮,我就无法添加新行或删除一些行。有没有人为的方式来实现我的目标?

【问题讨论】:

    标签: c# .net winforms datagridview combobox


    【解决方案1】:

    DataGridView 本身有很多方法可以实现这一点。

    1) 创建dropdownbox for one column type 并绑定typeof(enum) Create drop down list options from enum in a DataGridView

    2) 使用TypeConverter of EnumConverter Data bind enum properties to grid and display description

    其他几个,

    How to show Enum type members in a DataGridViewComboBox?

    How to display enum values in datagridview column

    【讨论】:

    • 如果我按照这种方式,我不能使用 dataGrid.Datasource = source;我需要手动进行所有数据同步,这是不可接受的。
    • 如果您想出更好的方法,请发布您的答案,以便社区受益。到目前为止,还没有这样的东西存在
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-28
    • 2016-12-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多