Click here to Skip to main content
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 22:32pm
Edited 5-Jun-13 22: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 OriginalGriff 277
1 Maciej Los 210
2 BillWoodruff 205
3 Jochen Arndt 180
4 DamithSL 165
0 OriginalGriff 5,130
1 DamithSL 4,157
2 Maciej Los 3,670
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,821


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 6 Jun 2013
Copyright © CodeProject, 1999-2014
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