Skip to content

DevExpress-Examples/winforms-grid-highlight-cell-values-matching-text-in-autofilterrow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WinForms Data Grid - Highlight cell text that matches the filter (Auto Filter Row)

This example handles the CustomDrawCell event to highlight cell text that matches the text in the corresponding cell in the auto filter row.

WinForms Data Grid - Highlight text in cells that match the filter (Auto Filter Row)

private void gridView1_CustomDrawCell(object sender, RowCellCustomDrawEventArgs e) {
    GridView view = (GridView)sender;
    if (!view.OptionsView.ShowAutoFilterRow || !view.IsDataRow(e.RowHandle))
        return;

    string filterCellText = view.GetRowCellDisplayText(GridControl.AutoFilterRowHandle, e.Column);
    if (String.IsNullOrEmpty(filterCellText))
        return;

    int filterTextIndex = e.DisplayText.IndexOf(filterCellText, StringComparison.CurrentCultureIgnoreCase);
    if (filterTextIndex == -1)
        return;
    e.Appearance.FillRectangle(e.Cache, e.Bounds);
    e.Cache.Paint.DrawMultiColorString(e.Cache, e.Bounds, e.DisplayText, filterCellText, e.Appearance, Color.Black, Color.Gold, false, filterTextIndex);
    e.Handled = true;
}

Files to Review

Documentation