i have a bound dataviewgrid with a checkboxcolumn. when the user clicks a
checkbox if the value is true i want a button to be enabled. the logic is:
1-loop through checkboxcolumn cells
2-if the cell value is true enable the button and exit loop
3-if there were no checked cells disable the button
the problem is that the value returned by the checkbox cell is always false.
here is my code thus far:
Private Sub oGrid_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles oGrid.Click
Dim oGrd As DataGridView
Dim bEnabled As Boolean = False
If sender.GetType.IsInstanceOfType(New DataGridView) Then
oGrd = sender
If oGrd.CurrentCell.GetType.IsInstanceOfType(New
DataGridViewCheckBoxCell) Then
For Each oRow As DataGridViewRow In oGrd.Rows
If oRow.Cells("APPROVEDDataGridViewCheckBoxColumn").Value = True
Then
bEnabled = True
Exit For
End If
Next oRow
btnOk.Enabled = bEnabled
End If
End If
End Sub
Hi,
>i have a bound dataviewgrid with a checkboxcolumn. when the user clicks a
> checkbox if the value is true i want a button to be enabled. the logic
[quoted text clipped - 4 lines]
> the problem is that the value returned by the checkbox cell is always
> false.
Are you saying that DGVCheckBoxCell.Value always returns false, or do you
mean that only the editing cell doesn't return the right value, there's a
difference.
To handle editing cells, you better handle DataGridView.CellContentClick and
check DGVCheckBoxCell.EditingCellFormattedValue.
If you are starting out with a complete unchecked grid, you could use the
above event and increase/decrease a counter so you don't need to loop all
rows.
HTH,
Greetings
> here is my code thus far:
>
[quoted text clipped - 17 lines]
> End If
> End Sub
stockbuildingsupply - 21 Feb 2006 20:57 GMT
Thanks Bart,
The EditingCellFormattedValue did what I needed. In addition I took your
suggestion and implemented a counter to keep track instead of having to
iterate each time.
> Hi,
>
[quoted text clipped - 42 lines]
> > End If
> > End Sub