Category / Section
How to prevent the cell or column from being a part of the selection in WinForms GridControl?
1 min read
Prevent the grid cell or column
In GridControl, you can use the grid’s SelectionChanging event to cancel a selection depending upon the criteria that you have specified.
C#
void gridControl1_SelectionChanging(object sender, GridSelectionChangingEventArgs e) { //prevent cell from selection if(e.Range.Contains(GridRangeInfo.Cell(2,2))) e.Cancel=true; //prevent column from selection if(e.Range.IntersectsWith(GridRangeInfo.Col(3))) e.Cancel=true; }
VB
Private Sub gridControl1_SelectionChanging(ByVal sender As Object, ByVal e As GridSelectionChangingEventArgs) 'prevent cell from selection If e.Range.Contains(GridRangeInfo.Cell(2,2)) Then e.Cancel=True End If 'prevent column from selection If e.Range.IntersectsWith(GridRangeInfo.Col(3)) Then e.Cancel=True End If End Sub
Samples: