0

I have three columns in my dgv; two of the columns contain text, and the third has a button.

The button in the dgv works fine, however, if I click on text in any of my other columns; that text behaves as if it were the button.

I'm using the CellContentClick event to go to another form. Is there another event that I could use that is specific to only one column? Or should I just identify in the code which column I would like the button to respond to? ...and if so, how would I do this?

Ayyappan Subramanian
  • 5,348
  • 1
  • 22
  • 44
John
  • 447
  • 2
  • 8
  • 20
  • `CellContentClick` is the best choice http://stackoverflow.com/questions/3577297/how-to-handle-click-event-in-button-column-in-datagridview – Robert P Apr 03 '15 at 15:40
  • @RobertP I used the code in the link you provided and it works, but it impairs the editing functionality on the dgv. Any other suggestions? – John Apr 03 '15 at 15:50

1 Answers1

2

You must identify the clicked column. You can do it this way :

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
    if (e.ColumnIndex == yourButtonsColumn.Index)
    {
        ...
    }
}
Bioukh
  • 1,888
  • 1
  • 16
  • 27