Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
DatagridViewCheckobxColumn Mysteries
Message
De
18/05/2014 13:36:10
John Baird
Coatesville, Pennsylvanie, États-Unis
 
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Versions des environnements
Environment:
VB 9.0
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01600182
Message ID:
01600183
Vues:
40
>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__

Haven't done winforms in quite a while, but IIRC there is an EndEdit or EndCellEdit (something like that) event.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform