0

I am having a DataGridView with 3 columns. Delete, User Name, Password. Delete column hosts a CheckBox, the other 2 are text. The DataGridView is named grid1.

I am trying to check if user has clicked the CheckBox field by using event handler. Problem is that I'm not sure what should I use to add handler to. Should I use grid.(...) or Delete.(...) and which property of should I use? Which event handler?

1 Answer 1

1

Try handling the DataGridView CellContentClick event:

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { MessageBox.Show(e.RowIndex.ToString()+" and "+e.ColumnIndex.ToString()); } 

You then need to test the column index to check it is your checkbox column.

You can get the checked state of each checkbox by inspecting the 'value' of each cell:

foreach (DataGridViewRow dataGridRow in dataGridView1.Rows) { var checked = ((DataGridViewCheckBoxColumn)dataGridRow.Cells["checkbox_col"]).Value; } 
Sign up to request clarification or add additional context in comments.

1 Comment

Why iterate over all cells? You can just use the CellValueChanged event and get the rowindex and column index from it's args.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.