Change default filter operator in RadVirtualGrid for WinForms
Environment
Product Version | Product | Author |
---|---|---|
2024.4.1127 | RadVirtualGrid for WinForms | Nadya Todorova |
Description
When performing filtering in RadVirtualGrid, the client may want to change the FilterOperator that is shown by default.
Solution
In order to change the default filter operator for a particular column in RadVirtualGrid, you can use a custom VirtualGridFilterCellElement. Please refer to the following article for more information about how to create a custom cells: Creating custom cells
In this case, you need to create a custom VirtualGridFilterCellElement and override its UpdateInfo(). Follow these steps to implement the solution where the FilterOperatorText is changed to DoesNotContain:
private void RadVirtualGrid1_CreateCellElement(object sender, VirtualGridCreateCellEventArgs e)
{
if (e.CellType == typeof(VirtualGridFilterCellElement))
{
e.CellElement = new CustomVirtualGridFilterCellElement();
}
}
public class CustomVirtualGridFilterCellElement : VirtualGridFilterCellElement
{
protected override Type ThemeEffectiveType
{
get
{
return typeof(VirtualGridFilterCellElement);
}
}
protected override void UpdateInfo(VirtualGridCellValueNeededEventArgs args)
{
base.UpdateInfo(args);
if (this.Descriptor == null)
{
Type columnType = this.ViewInfo.GetColumnDataType(this.ColumnIndex);
if (this.ColumnIndex == 0)
{
RadVirtualGridLocalizationProvider currentProvider = RadVirtualGridLocalizationProvider.CurrentProvider;
string text = currentProvider.GetLocalizedString(RadVirtualGridStringId.FilterFunctionDoesNotContain);
this.FilterOperatorText.Text = text + ":";
}
}
}
}