I have a DataGridView with five columns defined. The user populates the DataGridView at runtime by selecting one or more files through an openFileDialog and the file name(s) are loaded into the first column of the DataGridView. The second and third columns contain checkboxes to indicate how the file name should be processed. The true value is 1 and false is 0. However, the user needs to only be able to select one of the two checkboxes for each file name. If the user checks one of the checkboxes, I want the other checkbox, if checked, to become unchecked. Here is my code below. It doesn't generate any errors and, when it occasionally makes a checkbox become unchecked when another is checked, it may uncheck another checkbox in the same or the other column, but never in the same row. I need to learn to use the debugger and will work on that now while I'm stumped, but would appreciate any help that I can receive in the meantime: private void dataGridViewInputReports_CellValueChanged(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0 && e.ColumnIndex > 0 && e.ColumnIndex < 3) { if (Convert.ToInt16(dataGridViewInputReports.Rows[e.RowIndex].Cells[e.ColumnIndex].Value) == 1) { if (e.ColumnIndex == 1) { dataGridViewInputReports.Rows[e.RowIndex].Cells[2].Value = 0; } else if (e.ColumnIndex == 2) { dataGridViewInputReports.Rows[e.RowIndex].Cells[1].Value = 0; } } } }
mercredi 25 février 2015
How to have only one of two DataGridViewCheckBox columns checked or true in a DataGridView
Inscription à :
Publier les commentaires (Atom)
Aucun commentaire:
Enregistrer un commentaire