/winforms-grid-hot-track-focused-column-header

Highlight the focused column header in the WinForms Grid Control.

Primary LanguageVisual Basic .NETOtherNOASSERTION

WinForms Data Grid - Highlight the focused column header

This example handles the CustomDrawColumnHeader event to apply a hot-track state for the focused column.

The example also handles FocusedColumnChanged and Layout events to call the InvalidateColumnHeader mehthod to forcibly repaint column headers when the focused column or the GridView's layout is changed.

WinForms Data Grid - Highlight the focused column header

private void gridView1_CustomDrawColumnHeader(object sender, ColumnHeaderCustomDrawEventArgs e) {
    GridView view = sender as GridView;
    if (e.Column?.FieldName == view.FocusedColumn.FieldName)
        e.Info.State = ObjectState.Hot;
}
private void gridView1_FocusedColumnChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedColumnChangedEventArgs e) {
    ((GridView)sender).InvalidateColumnHeader(e.FocusedColumn);
    ((GridView)sender).InvalidateColumnHeader(e.PrevFocusedColumn);
}
private void gridView1_Layout(object sender, EventArgs e) {
    ((GridView)sender).InvalidateColumnHeader(null);
}

Files to Review

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)