none
DataGridViewButtonCell Click Event RRS feed

  • Question

  • Hi,

     

     I have a DataGriDview, which on  Form2_Load() event shows some columns bound with data and one DataGriDviewButtonColumn.

     

    Is there EXIST any CLICKEVENT for DataGridViewButtonColumn Cells.

     

    On Click on the Buttons I want to take a  value from the row of respective DatagridViewButton and communicate with another form How to accomplish it please help.

    Tuesday, July 31, 2007 3:51 PM

Answers

  • you want to use the datagridview cellcontentclick event.  and execute your logic if the button cell was clicked.  the following code snippet should give you some idea.

     


            private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
            {
                // find out which column was clicked
                if (dataGridView1.Columns[e.ColumnIndex] == Column1)
                {
                    //get the value which you want to display
                    String customer = (String) dataGridView1.Rows[e.RowIndex].Cells[2].Value;
                   
                    // display on the new form.
                    Form form2 = new Form();
                    form2.Text = customer;
                    form2.ShowDialog();
                   
                }
            }

     

     

    Tuesday, July 31, 2007 11:13 PM

All replies

  • you want to use the datagridview cellcontentclick event.  and execute your logic if the button cell was clicked.  the following code snippet should give you some idea.

     


            private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
            {
                // find out which column was clicked
                if (dataGridView1.Columns[e.ColumnIndex] == Column1)
                {
                    //get the value which you want to display
                    String customer = (String) dataGridView1.Rows[e.RowIndex].Cells[2].Value;
                   
                    // display on the new form.
                    Form form2 = new Form();
                    form2.Text = customer;
                    form2.ShowDialog();
                   
                }
            }

     

     

    Tuesday, July 31, 2007 11:13 PM
  • Hi,

     

    The   dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) event runs on clicking on any of the cells.

     

    Can I disable this events for all the columns except the button column.

     

    Wednesday, August 1, 2007 8:44 AM
  • i think you cannot do this. that is the reason, in the code snippen i provided, i checked the column where the event originated.

     

    Wednesday, August 1, 2007 5:37 PM
  • HI i am also face same issue. even my DataGridViewButtonColumn(Edit button) is in 4th column. and in CellContentClick e.Columnindex shows me 0. also can please tell me in below code what is Column1?? and in Column1 which data comes.

     private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
            {
                // find out which column was clicked
                if (dataGridView1.Columns[e.ColumnIndex] == Column1)
                {
                    //get the value which you want to display
                    String customer = (String) dataGridView1.Rows[e.RowIndex].Cells[2].Value;
                    
                    // display on the new form.
                    Form form2 = new Form();
                    form2.Text = customer;
                    form2.ShowDialog();
                    
                }
            }

    Thanks in advance.

    Wednesday, September 12, 2012 9:05 AM