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

Highlight cell text that matches the filter in the grid's Auto Filter Row.

Primary LanguageVisual Basic .NETOtherNOASSERTION

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

Does this example address your development requirements/objectives?

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