DataTable _carsTable;
public Form1()
{
InitializeComponent();
this.Load += Form1_Load;
}
private void Form1_Load(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection(
"provider=microsoft.jet.oledb.4.0;Data Source=" +
Environment.GetFolderPath(Environment.SpecialFolder.Personal) +
"\\ComponentOne Samples\\Common\\C1NWind.mdb");
_carsTable = new DataTable();
new OleDbDataAdapter("Select * from Cars", con).Fill(_carsTable);
c1DataFilter1.DataSource = GetCars().ToList();
c1FlexGrid1.DataSource = GetCars().ToList();
//Initializes the Custom Model filter. This filter
//allows you to filter the car models using the
//MultiSelect control
var modelFilter = new ModelFilter()
{
HeaderText = "Model",
PropertyName = "Model",
};
//Sets the data for the MultiSelect control
modelFilter.SetTagList(GetCars().ToList());
//Customizes the MultiSelect control to display
//not more than 5 items in the control's header
modelFilter.MultiSelect.MaxHeaderItems = 5;
//Adds the custom filter to the FilterCollection
c1DataFilter1.Filters.Add(modelFilter);
//Subscribe to the FilterChanged event
c1DataFilter1.FilterChanged += C1DataFilter1_FilterChanged;
}
private void C1DataFilter1_FilterChanged(object sender, EventArgs e)
{
//Updates the data aware control with filtered data
c1FlexGrid1.DataSource = c1DataFilter1.View.Cast<Car>().ToList();
}
public IEnumerable<Car> GetCars()
{
var carsTable = _carsTable;
foreach (DataRow row in carsTable.Rows)
{
yield return new Car
{
Brand = row.Field<string>("Brand"),
Category = row.Field<string>("Category"),
Description = row.Field<string>("Description"),
Liter = row.Field<double>("Liter"),
Model = row.Field<string>("Model"),
Picture = row.Field<byte[]>("Picture"),
Price = row.Field<double>("Price"),
TransmissAutomatic = row.Field<string>("TransmissAutomatic"),
ID = row.Field<int>("ID")
};
}
}