【问题标题】:Create an event for a DataGridViewButtonCell in VB.Net在 VB.Net 中为 DataGridViewButtonCell 创建一个事件
【发布时间】:2013-08-12 14:52:27
【问题描述】:

我有一个 DataGridViewButtonColumn,但我需要它在单击时做出响应,以便我可以执行代码。有人可以帮忙吗?

【问题讨论】:

  • 你能给我们一些代码吗?

标签: .net vb.net events datagrid


【解决方案1】:

如果你想使用 datagridviewcellcontentclick 事件。如果单击按钮单元格,则执行您的逻辑。下面的代码 sn-p 应该会给你一些想法。

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
// find out which column was clicked
if (dataGridView1.Columns[e.ColumnIndex] == Column1)
{
 //get the value which you want to display
 String customer = (String) dataGridView1.Rows[e.RowIndex].Cells[2].Value;

 // display on the new form.
 Form form2 = new Form();
 form2.Text = customer;
 form2.ShowDialog();

 }
}

【讨论】:

  • 完美!正是我想要的。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-11-23
  • 1970-01-01
  • 1970-01-01
  • 2015-02-15
  • 1970-01-01
  • 1970-01-01
  • 2011-05-20
相关资源
最近更新 更多