本文介绍了datagridview按钮列Winforms的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 DataGridView 上有一个按钮列,我试图处理一个 Button.Click 发生在我点击按钮。任何帮助?

I have a button column on a DataGridView and I am trying to handle a Button.Click event but nothing happens when I click a button. Any help?

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 ");
    }
}


推荐答案

I已尝试您的样本,它的工作原理。您确实将事件绑定到 DataGridView

I have tried your sample and it works. Did you really bind the event to your DataGridView ?

请检查 InitializeComponent < YourFormName> .Designer.cs 类中的方法。
它真的有

Please check the InitializeComponent() Method in your <YourFormName>.Designer.cs class.Did it really has

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

并且你不会在代码中的另一个地方删除处理程序?

and you don't remove the handler at another place in code ?

MSDN页面中的DataGridViewButtonColumn可以这样说:

The DataGridViewButtonColumn MSDN page has this to say:

这篇关于datagridview按钮列Winforms的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 18:37