[DEVEXPRESS] Hướng dẫn Hightlight text khi lọc tự động trên các dòng GridView
Xin chào các bạn, bài này mình sẽ hướng dẫn các bạn cách tô màu hightlight lên dữ liệu mà chúng ta gõ tìm kiếm trong AutoFilter của GridView Devexpress.
Mặc định trong GridView, khi chúng ta bật chức năng Autofilter trong Grid, thì khi chúng ta tìm kiếm nó không có tô màu.
Mình sẽ hướng dẫn các bạn tô màu, để làm cho người dùng dễ dàng tìm thấy cụm từ mà người ta tìm kiểm dễ dàng.
Giao diện Auto Filter hightlight GridView C#:
Trong GridView các bạn thêm sự kiện gridView1_CustomDrawCell với source code C#:
private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.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;
XPaint.Graphics.DrawMultiColorString(e.Cache, e.Bounds, e.DisplayText, filterCellText, e.Appearance, Color.Black, Color.Gold, false, filterTextIndex);
e.Handled = true;
}
- Ở dòng XPaint.Graphics.DrawMultiColorString(e.Cache, e.Bounds, e.DisplayText, filterCellText, e.Appearance, Color.Black, Color.Gold, false, filterTextIndex);
Các bạn có thể thay đổi background và màu sắc ở dòng này.
HAPPY CODING