Skip to content

Latest commit

 

History

History
48 lines (34 loc) · 2.98 KB

File metadata and controls

48 lines (34 loc) · 2.98 KB

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)