'Declaration Public Class C1DataFilter Inherits C1.Framework.XViewHost
public class C1DataFilter : C1.Framework.XViewHost
'Declaration Public Class C1DataFilter Inherits C1.Framework.XViewHost
public class C1DataFilter : C1.Framework.XViewHost
private void InitializeDataFilter()
{
//Initialize the DataFilter Control
c1DataFilter1 = new C1DataFilter();
c1DataFilter1.Dock = DockStyle.Fill;
splitContainer1.Panel1.Controls.Add(c1DataFilter1);
//Set the datasource of the DataGridView
dataGridView1.DataSource = _carsTable;
//Setting AutoGenerateFilters to true generates the filters automatically.
c1DataFilter1.AutoGenerateFilters = true;
//Subscribe to the FilterAutoGenerating event to modify the automatically generated filters.
c1DataFilter1.FilterAutoGenerating += C1DataFilter1_FilterAutoGenerating;
//Set the datasource of C1DataFilter equal to the datasource assigned to DataGridView
c1DataFilter1.DataSource = _carsTable;
//Automatically applies the filter to the DataSource after the filter value is changed.
c1DataFilter1.AutoApply = true;
//Shows the DataFilter header
c1DataFilter1.ShowHeader = true;
//Sets the header text of the DataFilter control
c1DataFilter1.HeaderText = "Refine by";
//Styling the DataFilter and its elements
c1DataFilter1.Styles.Common.Border = new C1.Framework.Thickness(5);
c1DataFilter1.Styles.Header.Font = new Font(FontFamily.GenericSansSerif, 9f, FontStyle.Bold);
c1DataFilter1.Styles.FilterCaption.BackColor = Color.LightCyan;
}
private void C1DataFilter1_FilterAutoGenerating(object sender, C1.DataFilter.FilterAutoGeneratingEventArgs e)
{
switch (e.Property.Name)
{
//Set the checklist items for Brand filter
case "Brand":
var brandFilter = (C1.Win.DataFilter.ChecklistFilter) e.Filter;
brandFilter.ItemsSource = _carsTable;
brandFilter.ValueMemberPath = "Brand";
brandFilter.SelectAll();
break;
//Set the checklist items for Category filter
case "Category":
var categoryFilter = (C1.Win.DataFilter.ChecklistFilter) e.Filter;
categoryFilter.ItemsSource = _carsTable;
categoryFilter.ValueMemberPath = "Category";
categoryFilter.SelectAll();
break;
//Set the minimum/maximum value for the Price filter
case "Price":
var priceFilter = (C1.Win.DataFilter.RangeFilter) e.Filter;
priceFilter.Maximum = _carsTable.AsEnumerable().Max(x = >x.Field < double > ("Price"));
priceFilter.Minimum = _carsTable.AsEnumerable().Min(x = >x.Field < double > ("Price"));
priceFilter.Increment = 1000;
priceFilter.Digits = 0;
break;
//Cancels the creation of all other filters
default:
e.Cancel = true;
break;
}
}
private void SaveFilterExpression()
{
//Saves the current filter expressions to an XML file
c1DataFilter1.SaveFilterExpression("SavedFilters.xml");
}
private void LoadFilterExpression()
{
//Loads the current filter expressions from an XML file
c1DataFilter1.LoadFilterExpression("SavedFilters.xml");
}
System.Object
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.Control
C1.Framework.XViewHost
C1.Win.DataFilter.C1DataFilter