【问题标题】:Add button column to datatable将按钮列添加到数据表
【发布时间】:2012-04-11 10:25:23
【问题描述】:

我试图在数据表中插入一个按钮列,但它说这是一个错误。请问有什么帮助吗?

        ButtonColumn col = new ButtonColumn();
        col.CommandName = "select";
        col.ButtonType = ButtonColumnType.LinkButton;
        col.HeaderText = "Edit";
        dt.Columns.Add(col);

【问题讨论】:

  • 1.你真的没有添加到datatable 你需要将它添加到数据网格。 2. 介意分享一下您遇到了什么错误或我们需要猜测吗?
  • 如果你得到你想要的信息,不要忘记将答案标记为已接受......

标签: c# c#-4.0 datatable


【解决方案1】:

在 DataTable 中添加 Buttoncolumn 其有线...这根本不可能...

DataTable DataColumn DataType 属性支持以下基本 .NET Framework 数据类型:

  1. 布尔值
  2. 字节
  3. 字符
  4. 日期时间
  5. 十进制
  6. 双
  7. Int16
  8. Int32
  9. Int64
  10. SByte
  11. 单人
  12. 字符串
  13. 时间跨度
  14. UInt16
  15. UInt32
  16. UInt64

添加列的示例代码

DataTable workTable = new DataTable("Customers"); 
DataColumn workCol = workTable.Columns.Add("CustID", typeof(Int32));
workCol.AllowDBNull = true;

【讨论】:

  • 我认为 OP 实际上试图将列添加到 datagrid-datasource 是数据表,所以这就是为什么 :)
  • @Reniuz - 我正在等待来自操作方的更新,以便我可以根据该更新我的答案......
  • 我在上面的列表中缺少Byte[]。 msdn.microsoft.com/en-us/library/…
【解决方案2】:

您只能在DataGrid 上添加button,而不是DataTable。

【讨论】:

    猜你喜欢
    • 2018-07-06
    • 2014-08-05
    • 2016-05-22
    • 2014-01-06
    • 2011-08-11
    • 1970-01-01
    • 2014-09-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多