Click here to Skip to main content
11,713,845 members (85,720 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.0
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!

        }
Posted 5-Jun-13 21:32pm
Edited 5-Jun-13 21:38pm
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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!
Smile | :)
  Permalink  
Comments
Member 9956178 at 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!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  
v2
Comments
Member 9956178 at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 370
1 CHill60 250
2 Maciej Los 229
3 Richard MacCutchan 210
4 OriginalGriff 175
0 Sergey Alexandrovich Kryukov 365
1 CHill60 335
2 OriginalGriff 245
3 Andy Lanng 173
4 Richard MacCutchan 150


Advertise | Privacy | Mobile
Web01 | 2.8.150819.1 | Last Updated 6 Jun 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100