按钮单击事件在DATAGRIDVIEW中不起作用(使用EditingControlShowing) [英] Button Click event is NOT WORKING in DATAGRIDVIEW (using EditingControlShowing)

查看:77
本文介绍了按钮单击事件在DATAGRIDVIEW中不起作用(使用EditingControlShowing)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我熟悉asp绑定的feild和模板feilds ..我是新手独立应用程序..

我的数据网格中有以下代码和2个按钮coloums,我不想使用单元格内容

点击事件...我想这样做Bt我无法找到解决方案..

是否需要一些设置?

Plz帮助

提前谢谢



  private   void  dataGridView1_EditingControlShowing( object  sender,DataGridViewEditingControlShowingEventArgs e)
{


如果(e.Control 按钮)
{

按钮btndelete = e.Control as 按钮;
btndelete.Click - = new EventHandler(btndelete_Click);


按钮btnupdate = e.Control as 按钮;
btnupdate.Click + = new EventHandler(btnupdate_Click);
}
}

私有 void btndelete_Click( object sender,EventArgs e)
{

int col = this .dataGridView1.CurrentCell.ColumnIndex;

int row = this .dataGridView1.CurrentCell.RowIndex;

MessageBox.Show( 单元格中的按钮[ +

col.ToString()+ +

row.ToString()+ ]已被点击);
// 此处将触发删除代码!

}

解决方案

有一个事件cellclick fr datagridview使用

  private   void  datagridview1_CellClick( object  sender,EventArgs e)
{
int col = this .dataGridView1.CurrentCell.ColumnIndex;
int row = this .dataGridView1.CurrentCell.RowIndex;
if (col = 5 // 而不是5使用按钮列的列索引
{
MessageBox.Show( 单元格中的按钮[ +

col.ToString()+ +

row.ToString()+ ]已被点击);
// 删除代码将在这里解雇!
}
}



快乐编码!

:)


看到这些..

向C#DataGridView添加按钮 [ ^ ]

如何处理Datagridview中按钮列中的点击事件? [ ^

I am familiar with asp bound feild and template feilds..I am new to stand alone applications..
I have the following code and 2 button coloums in my datagrid,I do not want to use cell content
click event...I want to do it like this Bt I''m unable to find a solution..
is some setting required?
Plz help
Thankx in advance

private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
           
            
            if (e.Control is Button )
            {

                Button btndelete = e.Control as Button;
                btndelete.Click -= new EventHandler(btndelete_Click);
             
            
                Button btnupdate = e.Control as Button;
                btnupdate.Click += new EventHandler(btnupdate_Click);
            }
        }

        private void btndelete_Click(object sender, EventArgs e)
        {

            int col = this.dataGridView1.CurrentCell.ColumnIndex;

            int row = this.dataGridView1.CurrentCell.RowIndex;

            MessageBox.Show("Button in Cell[" +

                col.ToString() + "," +

                row.ToString() + "] has been clicked");
           // code for delete will be fired here!

        }

解决方案

there is an event cellclick fr datagridview use that

private void datagridview1_CellClick(object sender, EventArgs e)
      {
          int col = this.dataGridView1.CurrentCell.ColumnIndex;
          int row = this.dataGridView1.CurrentCell.RowIndex;
if ( col = 5) //instead of 5 use column index of button column
{
          MessageBox.Show("Button in Cell[" +

              col.ToString() + "," +

              row.ToString() + "] has been clicked");
         // code for delete will be fired here!
}
      }


Happy Coding!
:)


See these..
Add Button to C# DataGridView[^]
How to handle click event in Button Column in Datagridview?[^]


这篇关于按钮单击事件在DATAGRIDVIEW中不起作用(使用EditingControlShowing)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆