windowsforms-3030-controls-and-libraries-data-grid-examples-painting-how-to-custom-paint-row-indicators.md
This example illustrates how to apply custom colors to row indicators. You can test this sample in the Custom painting - CustomDrawRowIndicator Data Grid demo.
private void Form3_Load1(object sender, EventArgs e) {
CustomDrawRowIndicator(gridControl1, gridView1);
}
public static void CustomDrawRowIndicator(GridControl gridControl, GridView gridView) {
gridView.IndicatorWidth = 50;
// Handle this event to paint RowIndicator manually
gridView.CustomDrawRowIndicator += (s, e) => {
if (!e.Info.IsRowIndicator) return;
GridView view = s as GridView;
e.Handled = true;
e.Appearance.BackColor = view.FocusedRowHandle == e.RowHandle ? Color.Chocolate : Color.MediumSpringGreen;
e.Appearance.FillRectangle(e.Cache, new Rectangle(e.Bounds.X + 2, e.Bounds.Y + 2, e.Bounds.Width - 4, e.Bounds.Y - 4));
if (e.Info.ImageIndex < 0) return;
ImageCollection ic = e.Info.ImageCollection as ImageCollection;
Image indicator = ic.Images[e.Info.ImageIndex];
e.Cache.DrawImage(indicator, new Rectangle(e.Bounds.X + 20, e.Bounds.Y + 6, indicator.Width, indicator.Height));
};
}
Private Sub Form3_Load1(ByVal sender As Object, ByVal e As EventArgs)
CustomDrawRowIndicator(gridControl1, gridView1)
End Sub
Public Shared Sub CustomDrawRowIndicator(ByVal gridControl As GridControl, ByVal gridView As GridView)
gridView.IndicatorWidth = 50
' Handle this event to paint RowIndicator manually
AddHandler gridView.CustomDrawRowIndicator, Sub(s, e)
If Not e.Info.IsRowIndicator Then
Return
End If
Dim view As GridView = TryCast(s, GridView)
e.Handled = True
e.Appearance.BackColor = If(view.FocusedRowHandle = e.RowHandle, Color.Chocolate, Color.MediumSpringGreen)
e.Appearance.FillRectangle(e.Cache, New Rectangle(e.Bounds.X + 2, e.Bounds.Y + 2, e.Bounds.Width - 4, e.Bounds.Y - 4))
If e.Info.ImageIndex < 0 Then
Return
End If
Dim ic As ImageCollection = TryCast(e.Info.ImageCollection, ImageCollection)
Dim indicator As Image = ic.Images(e.Info.ImageIndex)
e.Cache.DrawImage(indicator, New Rectangle(e.Bounds.X + 20, e.Bounds.Y + 6, indicator.Width, indicator.Height))
End Sub
End Sub