i have a checkboxcolumn in a datagridview, once i check one of the checkboxes in that column, how do i make that other checked boxes to be unchecked?

i was doing sothing as below

                foreach (DataGridViewRow row in dgvEmerContact.Rows)
                        dgvEmerContact.Rows[0].Cells[0].Value = bool.Parse(dgvEmerContact.Rows[r].Cells[0].Value.ToString());

didn't work

appreciate a reply,

5 Years
Discussion Span
Last Post by JOSheaIV

yes but there isn't an option in the datagrid view to select as it as a option


You need to add an event like ItemChecked that links to all your checkBoxes. I can't write out the code at the moment (lol don't have time), but I can explain the concept quickly.

So have an ItemChecked event (this is a checkedListBox event but you should be able to use the same or a similar one). When a box is checked first determine if it's being checked, if so store its index in a variable (make sure it's being checked only ... if you don't you'll have this executing on uncheck).

Then using a for loop or foreach, go through all the check boxes and uncheck them. Also make sure you implement an if statement before you uncheck the boxes, to check if the index you are on (in the loop) is the same as the box you just checked, if so DON'T uncheck this one

(if you still don't have later on, I'll come back and try and write up some code)

Edited by JOSheaIV


i thought there was a straingh way to approch this solution

yes i was also thingking this way, got it working


This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.