Hi
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)
                {
                    if(!string.IsNullOrEmpty(row.Cells[0].Value.ToString()))
                        dgvEmerContact.Rows[0].Cells[0].Value = bool.Parse(dgvEmerContact.Rows[r].Cells[0].Value.ToString());
                } 

didn't work

appreciate a reply,
thanks

Recommended Answers

All 5 Replies

Radio buttons only allow one to be selected, they are designed for this purpose.

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)

i thought there was a straingh way to approch this solution

yes i was also thingking this way, got it working

thanks

Sweet, that's good to hear! Sorry I wasn't able to help you with some actual code snippets

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.