Quote:
Originally Posted by maplecutie
how can I create the filter itself and to set filtering conditions using already described IFilter interface. I am using Dapfor .Net grid.
|
//User control for editing a filter.
public partial class CustomFilterControl : UserControl
{
private IWindowsFormsEditorService _service;
private CustomFilter _filterEditor;
private IFilter _currentFilter;
public CustomFilterControl()
{
InitializeComponent();
}
public IFilter CurrentFilter
{
get { return _currentFilter; }
}
public void EditFilter(IWindowsFormsEditorService service, CustomFilter filterEditor)
{
if (service != null)
{
//Display the control
_filterEditor = filterEditor;
_service = service;
service.DropDownControl(this);
}
}
//Called when the user clicks on the 'Ok' button
private void buttonOk_Click(object sender, EventArgs e)
{
if (_service != null)
{
//Create a filter and keep it in the _currentFilter variable
double minValue = (double)minValueCtrl.Value;
double maxValue = (double)maxValueCtrl.Value;
_currentFilter = new Ui.Filter(delegate(Row row)
{
double price = (double) row["Price"].Value;
if (minValue > 0 && price < minValue)
{
//filter the row, if the value less than the minValue.
return true;
}
if (maxValue > 0 && price > maxValue)
{
//filter the row, if the value less than the minValue.
return true;
}
return false;
});
//Close the dropdown control
_service.CloseDropDown();
}
}
}