使用EditingControlShowing

使用EditingControlShowing

本文介绍了按钮单击事件在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()+ ]已被点击);
// 此处将触发删除代码!

}
解决方案



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!

        }
解决方案



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

09-02 09:23