gpt4 book ai didi

c# - datagridview 按钮列 Winforms

转载 作者:行者123 更新时间:2023-11-30 22:32:03 24 4
gpt4 key购买 nike

我在 DataGridView 上有一个按钮列,我正在尝试处理 Button.Click 事件,但是当我单击按钮时没有任何反应。有帮助吗?

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
MessageBox.Show(e.ColumnIndex.ToString());
if (e.ColumnIndex == 5)
{
MessageBox.Show((e.RowIndex + 1) + " Row " + (e.ColumnIndex + 1) + " Column button clicked ");
}
}

最佳答案

我已经尝试了您的示例并且有效。你真的把事件绑定(bind)到你的 DataGridView 了吗? ?

请检查InitializeComponent()你的方法 <YourFormName>.Designer.cs类(class)。真的有吗

this.dataGridView1.CellClick += 
new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellClick);

并且您没有在代码的另一个地方删除处理程序?

DataGridViewButtonColumn MSDN 页面是这样说的:

To respond to user button clicks, handle the DataGridView.CellClick or DataGridView.CellContentClick event. In the event handler, you can use the DataGridViewCellEventArgs.ColumnIndex property to determine whether the click occurred in the button column. You can use the DataGridViewCellEventArgs.RowIndex property to determine whether the click occurred in a button cell and not on the column header.

关于c# - datagridview 按钮列 Winforms,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8909377/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com