【问题标题】:Is it possible to bind datatable to the ToolStripMenuItem?是否可以将数据表绑定到 ToolStripMenuItem?
【发布时间】:2011-05-05 17:23:48
【问题描述】:

我正在使用 ContextMenuStrip 并且我在运行时在 ContextMenuStrip 下创建了子菜单。通过添加 ToolStripMenuItem 类的对象。 我有一个来自该表的数据表,我想通过使用数据表中的 id 和 name 字段来填充我的子菜单,以便进一步处理应用程序。

有可能吗?

谢谢。

【问题讨论】:

    标签: c# winforms contextmenustrip


    【解决方案1】:

    试试这样的:

    foreach (DataRow dr in dataTable.Rows) {
                    cms.Items.Add(new ToolStripMenuItem() {
                        Text = dr["Name"].ToString()
                    });
                }
    

    【讨论】:

    • @Vale:谢谢,但我想添加多个字段。这可能吗?
    • @ Richa 你的意思是来自 DataRow 的字段吗?您可以像这样将多个字段作为 Text 属性添加到 ToolStripMenuItem:'Text = dr["Name"].ToString() + "-" + dr["ID"].ToString()' 这就是您的意思吗?跨度>
    • @Vale:没有。我的意思是我想将名称绑定到文本属性和 id 作为值成员。这可能吗?
    • @Richa ToolStripMenuItem 中没有值成员。
    • @Vale:你的意思是说这个问题没有解决方案?不是吗?
    猜你喜欢
    • 2013-01-30
    • 1970-01-01
    • 2011-03-12
    • 1970-01-01
    • 1970-01-01
    • 2021-12-13
    • 2012-09-01
    • 2011-02-17
    • 2017-02-28
    相关资源
    最近更新 更多