Category / Section
How to set the coveredrange cell in the rowheader to any other format in WinForms GridControl?
2 mins read
Customize the rowheader border style
You can set the WinForms Grid Control CoveredRange cell in the row header to any other format. You can set any shape to the row header by hiding the borders of the covered range cells. Actually, the headers do not have borders, but instead have a raised appearance that is part of their drawing code. So, to control the borders, change the CellType to something other than the header. Making the row header cell Static is one option. You can customize the cells styles by using the QueryCellInfo event.
C#
void Model_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e) { //Changes the Rowheader CellType and Bottom and right borders. if ((e.RowIndex == 0 && e.ColIndex > -1) || (e.RowIndex > 0 && (e.ColIndex == 0))) { e.Style.CellType = "Static"; e.Style.Borders.Bottom = new GridBorder(GridBorderStyle.Solid, Color.Green, GridBorderWeight.Medium); e.Style.Borders.Right = new GridBorder(GridBorderStyle.Dotted, Color.Red, GridBorderWeight.ExtraThick); } //Hides bottoms cells border. if ((e.RowIndex >= 2 && e.RowIndex < 5) && e.ColIndex == 0) { e.Style.Borders.Bottom = GridBorder.Empty; } //Hide right... if (e.RowIndex == 2 && e.ColIndex == 0) { e.Style.Borders.Right = GridBorder.Empty; } }
VB
Private Sub Model_QueryCellInfo(ByVal sender As Object, ByVal e As GridQueryCellInfoEventArgs) 'Changes the Rowheader CellType and Bottom and right borders. If (e.RowIndex = 0 AndAlso e.ColIndex > -1) OrElse (e.RowIndex > 0 AndAlso (e.ColIndex = 0)) Then e.Style.CellType = "Static" e.Style.Borders.Bottom = New GridBorder(GridBorderStyle.Solid, Color.Green, GridBorderWeight.Medium) e.Style.Borders.Right = New GridBorder(GridBorderStyle.Dotted, Color.Red, GridBorderWeight.ExtraThick) End If 'Hides bottoms cells border. If (e.RowIndex >= 2 AndAlso e.RowIndex < 5) AndAlso e.ColIndex = 0 Then e.Style.Borders.Bottom = GridBorder.Empty End If 'Hides right2... If e.RowIndex = 2 AndAlso e.ColIndex = 0 Then e.Style.Borders.Right = GridBorder.Empty End If End Sub
Samples: