Category / Section
How to change the selection border of the WinForms GridListControl?
1 min read
Change the selection border
In GridListControl, normally selection border is in dotted line if you need to customize the selection border of the GridListControl, you can use GridBorder which can be achieved by using the PrepareViewStyleInfo event.
C#
this.gridListControl1.Grid.PrepareViewStyleInfo += Grid_PrepareViewStyleInfo; void Grid_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e) { //Change the selection border if (this.gridListControl1.HasControlFocus && this.gridListControl1.Grid.CurrentCell.HasCurrentCellAt(e.RowIndex)) { GridBorder thinBorder = new GridBorder(GridBorderStyle.Solid, SystemColors.Highlight, GridBorderWeight.Thin); e.Style.Borders.Top = thinBorder; e.Style.Borders.Bottom = thinBorder; if (e.ColIndex == 1) e.Style.Borders.Left = thinBorder; if (e.ColIndex == gridListControl1.Grid.ColCount) e.Style.Borders.Right = thinBorder; } }
VB
AddHandler Me.gridListControl1.Grid.PrepareViewStyleInfo, AddressOf Grid_PrepareViewStyleInfo Private Sub Grid_PrepareViewStyleInfo(ByVal sender As Object, ByVal e As GridPrepareViewStyleInfoEventArgs) 'Change the selection border If Me.gridListControl1.HasControlFocus AndAlso Me.gridListControl1.Grid.CurrentCell.HasCurrentCellAt(e.RowIndex) Then Dim thinBorder As New GridBorder(GridBorderStyle.Solid, SystemColors.Highlight, GridBorderWeight.Thin) e.Style.Borders.Top = thinBorder e.Style.Borders.Bottom = thinBorder If e.ColIndex = 1 Then e.Style.Borders.Left = thinBorder End If If e.ColIndex = gridListControl1.Grid.ColCount Then e.Style.Borders.Right = thinBorder End If End If End Sub
Screenshot
Samples: