【问题标题】:How to select a WinForm DataGridView value, for a specific column, when anywhere along the entire row is clicked?当单击整行的任意位置时,如何为特定列选择 WinForm DataGridView 值?
【发布时间】:2011-08-28 05:14:15
【问题描述】:

我有一个简单的 WinForm 应用程序,上面有一个DataGridView。当用户在行结果中单击 -anywhere- 时,我希望检索恰好是该行 ID 的第一列的值(我将对其进行硬编码)。

有人对我如何做到这一点有任何建议吗?

假设 gridview 的 ID 是 DataGridView1

【问题讨论】:

  • .. 哇。很好奇为什么这会被否决...

标签: c# .net winforms datagridview


【解决方案1】:
private void DataGridView1_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
{

   var value= DataGridView1[ID_ColumnName.Index,e.RowIndex].Value
}

您也可以使用CellMouseClick 事件处理程序并使用相同的代码。

我希望你知道如何获取事件处理程序。

【讨论】:

  • 效果很好:) 我使用了CellMouseClick,是的,我知道如何连接它。干杯! (我在寻找一些 ROW 事件.. 不是单元格事件)。
猜你喜欢
  • 1970-01-01
  • 2012-11-20
  • 1970-01-01
  • 1970-01-01
  • 2012-06-10
  • 2013-11-27
  • 1970-01-01
  • 1970-01-01
  • 2018-08-24
相关资源
最近更新 更多