Skip to content

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

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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