Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
DatagridViewCheckobxColumn Mysteries
Message
 
To
All
General information
Forum:
ASP.NET
Category:
Forms
Title:
DatagridViewCheckobxColumn Mysteries
Environment versions
Environment:
VB 9.0
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01600182
Message ID:
01600182
Views:
41
I have a form with a dgv on it. The dgv has 1 column defined as a DataGridViewCheckBoxColumn. I would like this dgv to behave as a radiobutton group, i.e. when I click on one cell, that should be set to true, and the others to false.

I've got it to work fine ... as long as the user does not click twice on the same cell. When that happens, none of the checkboxes are set. It seems that after I assign my the values, the current event is still executed (i.e. the current checkbox is changed into false).
    Private Sub DataGridView1_CellContentClick(
        sender As Object, 
        e As DataGridViewCellEventArgs) 
        Handles DataGridView1.CellContentClick
        For Each r As DataGridViewRow In DataGridView1.Rows
            If r.Index = e.RowIndex Then
                r.Cells(0).Value = True
            Else
                r.Cells(0).Value = False
            End If
        Next
    End Sub
I would not mind assigning the values after the system has proccessed the event althogether, but I cannot find an event that gets triggered.

The answer might be "hidden" in here

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcheckboxcolumn(v=vs.110).aspx

but I cannot make any sense out of what they explain, so if anybody could translate this into plain English. :)
__quote__
Typically, check box cell values are intended either for storage, like any other data, or for performing bulk operations. If you want to respond immediately when users click a check box cell, you can handle the DataGridView.CellContentClick event, but this event occurs before the cell value is updated. If you need the new value at the time of the click, one option is to calculate what the expected value will be based on the current value. Another approach is to commit the change immediately, and handle the DataGridView.CellValueChanged event to respond to it. To commit the change when the cell is clicked, you must handle the DataGridView.CurrentCellDirtyStateChanged event. In the handler, if the current cell is a check box cell, call the DataGridView.CommitEdit method and pass in the Commit value.
__unquote__

If things have the tendency to go your way, do not worry. It won't last. Jules Renard.
Next
Reply
Map
View

Click here to load this message in the networking platform