Click here to Skip to main content
15,891,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

C#
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!

        }
Posted
Updated 5-Jun-13 21:38pm
v3

there is an event cellclick fr datagridview use that
C#
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!
:)
 
Share this answer
 
Comments
Member 9956178 6-Jun-13 4:57am    
I had done like this;in an alternative way.. and I wd also
like to know how to use Editshowing event.. Prb is that when I clik button Edit showing event does not get fired!
 
Share this answer
 
v2
Comments
Member 9956178 6-Jun-13 4:58am    
I had done like this;in an alternative way.. and I wd also like to know how to use Editshowing event.. Prb is that whenever I clik button at run time
Edit showing event does not get fired!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900