【问题标题】:Distinguish between DataGridViewButtonColumn and DataGridViewTextColumn cell click event区分 DataGridViewButtonColumn 和 DataGridViewTextColumn 单元格单击事件
【发布时间】:2014-03-12 11:38:26
【问题描述】:

我在 datagridview 控件中有 4 列,其中第 2 列是 datagridviewtext 列,而第 3 和第 4 列是 datagridviewbutton 列。 如何为 datagridviewbutton 单击触发不同的事件,并为 datagridviewtext 列触发不同的事件,因为它同时出现在 datagirdview 单元格内容单击中。 或以任何其他方式在 datagridview 单元格内容单击中查找按钮或文本单击。

【问题讨论】:

    标签: c# winforms datagridview


    【解决方案1】:

    CellContentClick 事件中,一种方法是检查单元格类型,如下所示:

    if (dataGridView1[e.ColumnIndex, e.RowIndex].GetType() == typeof(DataGridViewButtonCell)
    {
        // handle button cell click
    }
    else if (dataGridView1[e.ColumnIndex, e.RowIndex].GetType() == typeof(DataGridViewTextBoxCell)
    {
        // handle textbox cell click
    }
    

    其他细胞类型也一样。

    【讨论】:

      猜你喜欢
      • 2019-03-05
      • 2011-06-05
      • 2011-09-11
      • 1970-01-01
      • 1970-01-01
      • 2018-07-02
      • 1970-01-01
      • 2011-07-31
      • 2012-09-27
      相关资源
      最近更新 更多