Skip to content

Latest commit

 

History

History
41 lines (31 loc) · 3.02 KB

File metadata and controls

41 lines (31 loc) · 3.02 KB

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)