DevExpress-Examples / winforms-grid-rename-grid-filters-save-restore-layout

Rename grid filters and serialize custom names.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WinForms Data Grid - Rename grid filters and serialize custom names

When an end user applies a filter to a grid, the filter is shown within the Filter Panel. If the AllowMRUFilterList option is enabled, the user can access recently used filters and apply them.

This example shows how to allow the user to rename filters as needed:

Rename grid filters and serialize custom names

public partial class Main : XtraForm {
    FilterNameProvider provider;
    public Main() {
        InitializeComponent();
        gridView1.OptionsView.FilterCriteriaDisplayStyle = FilterCriteriaDisplayStyle.Text;
        recordBindingSource.DataSource = DataHelper.GetData(10);
        provider = new FilterNameProvider(gridView1) { AllowSettingFilterNames = true };
    }
}

The FilterNameProvider.GridFilters property is marked with the XtraSerializableProperty attribute. The following code serializes custom filter names with the grid layout:

void OnSaveLayoutButtonClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) {
    gridView1.SaveLayoutToXmlEx(provider, filePath);
}

The following code deserializes (restores) grid filters:

void OnRestoreLayoutButtonClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) {
    gridView1.RestoreLayoutFromXmlEx(provider, filePath);
}

GridFitlerItem objects are not created automatically. You should declare a special method in the FilterNameProvider class that creates such objects. Name this method according to the following pattern: "XtraCreateItem". In this example, this is the XtraCreateGridFiltersItem method:

internal GridFitlerItem XtraCreateGridFiltersItem(XtraItemEventArgs e) {
    GridFitlerItem fItem = new GridFitlerItem();
    GridFilters.Add(fItem);
    return fItem;
}

Files to Review

Documentation

About

Rename grid filters and serialize custom names.

License:Other


Languages

Language:Visual Basic .NET 51.9%Language:C# 48.1%