I just took a look at your original question
Which I interpret as one row, two checkboxes are to be looked at and not working against multiple rows. If I am not missing anything then why are you using a for statement to look at other column values?In DGV, I have 2 checkbox columns. Column1 and Column 2. Once I checked a checkbox in a column and it happens that there is already a checked checkbox in the other column and they are in the same ROW. It will automatically disable/uncheck the Checked Checkbox.. Meaning only One CheckBox must be allowed to be marked if happens that they are in the same row.
Working with one row, two checkboxes with a DataTable as the DataSource you can simply use logic similar to below to toggle the same row checkboxes
bsData is a BindingSource
Code:Private Sub DataGridView1_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged If DataGridView1.CurrentRow IsNot Nothing Then If e.ColumnIndex = DataGridView1.Columns("Check1").Index OrElse e.ColumnIndex = DataGridView1.Columns("Check2").Index Then Dim Row = bsData.CurrentRow If DataGridView1.CurrentRowCellValue("Check1") = "True" Then Row.Item("Check2") = False Else Row.Item("Check2") = True End If If DataGridView1.CurrentRowCellValue("Check2") = "True" Then Row.Item("Check1") = False Else Row.Item("Check1") = True End If bsData.DataTable.AcceptChanges() End If End If End Sub
Language extensions used in addition to those I already provided.
Code:Module BindingSourceExtensions <System.Diagnostics.DebuggerStepThrough()> _ <System.Runtime.CompilerServices.Extension()> _ Public Function DataTable(ByVal sender As BindingSource) As DataTable If sender.DataSource.GetType.Equals(GetType(System.Data.DataTable)) Then Return DirectCast(sender.DataSource, DataTable) Else Throw New Exception("DataSource is not a DataTable") End If End Function <System.Diagnostics.DebuggerStepThrough()> _ <System.Runtime.CompilerServices.Extension()> _ Public Function CurrentRow(ByVal sender As BindingSource) As DataRow Return CType((CType(sender.Current, DataRowView)).Row, DataRow) End Function End Module




Reply With Quote