terrydiederich2
1/10/2019 - 3:25 PM

DevExpress Red Border on Focused Row

Red Border on Focused Row

This involves the Paint event of the GridControl which for some reason is not exposed so you need to add an event handler when you initalize the form/user control.

Public Sub New()
    ' This call is required by the designer.
    InitializeComponent()

    ' Add any initialization after the InitializeComponent() call.
    gvEstimates.FocusRectStyle = DrawFocusRectStyle.RowFocus
    AddHandler gcEstimates.Paint, AddressOf gcEstimates_Paint
End Sub

Then in the Paint event add this code:

Private Sub gcEstimates_Paint(ByVal sender As Object, ByVal e As PaintEventArgs)
    Dim grid As GridControl = TryCast(sender, GridControl)
    Dim view As GridView = TryCast(grid.FocusedView, GridView)
    Dim viewInfo As GridViewInfo = TryCast(view.GetViewInfo(), GridViewInfo)
    Dim rowInfo As GridRowInfo = viewInfo.GetGridRowInfo(view.FocusedRowHandle)
    If rowInfo Is Nothing Then Return
    Dim r As Rectangle = Rectangle.Empty
    r = rowInfo.Bounds
    If r <> Rectangle.Empty Then
        r.Height -= 2
        r.Width -= 2
        e.Graphics.DrawRectangle(Pens.Red, r)
    End If
End Sub

To make the border wider, use a wider pen. You also have to invalidate the grid control to force a redraw. It seems to work best if you invalidate the grid control in the grid view's FocusedRowChanged event.

....
e.Graphics.DrawRectangle(New Pen(Color.Red, 2), r)
....

Private Sub MyGridView_FocusedRowChanged(sender As Object, e As Views.Base.FocusedRowChangedEventArgs) Handles gvEstimates.FocusedRowChanged
    Me.MyGridControl.Invalidate()
End Sub