this.gridGroupingControl1.TableModel.CellModels.Add("GridTableFilterBarCell", new GridTableFilterBarCellModel1(this.gridGroupingControl1.TableModel));
//Assigns the FilterBarCelltype as GridTableFilterBarCell
this.gridGroupingControl1.TableDescriptor.Appearance.FilterBarCell.CellType = "GridTableFilterBarCell";
public class GridTableFilterBarCellModel1 : GridTableFilterBarCellModel
{
public GridTableFilterBarCellModel1(Syncfusion.Windows.Forms.Grid.GridModel gm)
: base(gm)
{
}
//Overrides FillWithChoices to remove 'Custom' option from the list.
public override void FillWithChoices(ListBox listBox, GridStyleInfo style, out bool exclusive)
{
exclusive = true;
GridTableCellStyleInfo tableStyleInfo = (GridTableCellStyleInfo)style;
object[] items = (object[])GetFilterBarChoices(tableStyleInfo.TableCellIdentity);
listBox.Items.Clear();
if (items != null)
{
listBox.Items.Add(SelectAllText);
foreach (object item in items)
{
if (item != null && item != DBNull.Value)
listBox.Items.Add(style.GetFormattedText(item));
}
}
}
//Customizes the 'Select' method to hide the Custom option.
public void Select_WithoutCustom(GridTableCellStyleInfoIdentity tableCellIdentity, int index)
{
if (index >= 0)
{
if (index == 0)
{
ResetFilterBar(tableCellIdentity);
}
else
{
SelectItem(tableCellIdentity, index - 1);
}
}
}
public override GridCellRendererBase CreateRenderer(GridControlBase control)
{
return new Cellrenderer(control, this);
}
}
public class Cellrenderer : GridTableFilterBarCellRenderer
{
public Cellrenderer(GridControlBase grid, GridCellModelBase cellModel)
: base(grid, cellModel)
{
}
public new GridTableFilterBarCellModel1 Model
{
get
{
return (GridTableFilterBarCellModel1)base.Model;
}
}
//Overridse ListBoxMouseUP method to call Customized Select method instead of the usual 'Select' method.
protected override void ListBoxMouseUp(object sender, MouseEventArgs e)
{
CurrentCell.CloseDropDown(PopupCloseType.Done);
GridTableCellStyleInfo tableStyleInfo = (GridTableCellStyleInfo)this.StyleInfo;
GridTableCellStyleInfoIdentity tableCellIdentity = tableStyleInfo.TableCellIdentity;
Model.Select_WithoutCustom(tableCellIdentity, this.ListBoxPart.SelectedIndex);
SetTextBoxText(GetFilterBarText(StyleInfo), false);// don't call base class - ignore.
String _FilterBarValue = this.ListBoxPart.SelectedItem.ToString();
GridTableControl _grid = Grid as GridTableControl;
int _filed = _grid.TableDescriptor.ColIndexToField(ColIndex);
string _columnName = _grid.TableDescriptor.Columns[_filed].Name;
_grid.TableDescriptor.RecordFilters.Remove(_columnName);
if (_FilterBarValue != "(All)")
_grid.TableDescriptor.RecordFilters.Add(_columnName, FilterCompareOperator.Equals, this.ListBoxPart.SelectedItem);
}
} |