Category / Section
How to hold the row selection after the cell is deactivated in WinForms GridControl?
1 min read
Hold the row selection
In order to hold the row selection after the cell is deactivated, the SelectionChanging event can be used. The selection can be canceled by using Cancel property.
C#
// form() // Trigger the required event. gridControl1.Model.SelectionChanging += Model_SelectionChanging; void Model_SelectionChanging(object sender, GridSelectionChangingEventArgs e) { if (e.Reason == GridSelectionReason.MouseDown || e.Reason == GridSelectionReason.Clear) e.Cancel = true; }
VB
' form() ' Trigger the required event. Private gridControl1.Model.SelectionChanging += AddressOf Model_SelectionChanging Private Sub Model_SelectionChanging(ByVal sender As Object, ByVal e As GridSelectionChangingEventArgs) If e.Reason = GridSelectionReason.MouseDown OrElse e.Reason = GridSelectionReason.Clear Then e.Cancel = True End If End Sub
Screenshot
Sample links: