public class GridTableFilterBarCellModel1: GridTableFilterBarCellModel
{
public GridTableFilterBarCellModel1(Syncfusion.Windows.Forms.Grid.GridModel gm):base(gm)
{
}
// Override 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 is DBNull)
listBox.Items.Add(SelectEmptyText);
else if (item != null)
listBox.Items.Add(style.GetFormattedText(item));
}
}
}
// Customize 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 if (index == 1)
{
SelectItem(tableCellIdentity, 0);
}
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 Model.Form1.GridTableFilterBarCellModel1 Model
{
get
{
return (Model.Form1.GridTableFilterBarCellModel1) base.Model;
}
}
// Override 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);
// Don't call base class - ignore.
SetTextBoxText(GetFilterBarText(StyleInfo), false);
}
}
public override void FillWithChoices(ListBox listBox, GridStyleInfo style, out bool exclusive)
{
exclusive = true;
GridTableCellStyleInfo tableStyleInfo = (GridTableCellStyleInfo)style;
listBox.DataSource = null;
listBox.Items.Clear();
if (tableStyleInfo.DataSource != null)
{
Type listType = tableStyleInfo.DataSource.GetType();
if (listType.IsGenericType)
{
DataTable dt;
Type elementType = listType.GetGenericArguments()[0];
dt = new DataTable(elementType.Name + "List");
MemberInfo[] miArray = elementType.GetMembers(BindingFlags.Public | BindingFlags.Instance);
foreach (MemberInfo mi in miArray)
{
if (mi.MemberType == MemberTypes.Property)
{
PropertyInfo pi = mi as PropertyInfo;
dt.Columns.Add(pi.Name, pi.PropertyType);
}
else if (mi.MemberType == MemberTypes.Field)
{
FieldInfo fi = mi as FieldInfo;
dt.Columns.Add(fi.Name, fi.FieldType);
}
}
IList il = tableStyleInfo.DataSource as IList;
foreach (object record in il)
{
int i = 0;
object[] fieldValues = new object[dt.Columns.Count];
foreach (DataColumn c in dt.Columns)
{
MemberInfo mi = elementType.GetMember(c.ColumnName)[0];
if (mi.MemberType == MemberTypes.Property)
{
PropertyInfo pi = mi as PropertyInfo;
fieldValues[i] = pi.GetValue(record, null);
}
else if (mi.MemberType == MemberTypes.Field)
{
FieldInfo fi = mi as FieldInfo;
fieldValues[i] = fi.GetValue(record);
}
i++;
}
dt.Rows.Add(fieldValues);
listBox.DataSource = null;
}
listBox.DisplayMember = style.DisplayMember;
listBox.ValueMember = style.ValueMember;
if (string.IsNullOrEmpty(style.DisplayMember) && !string.IsNullOrEmpty(style.ValueMember))
{
listBox.DisplayMember = style.ValueMember;
}
listBox.BindingContext = this.BindingContext;
if (dt != null)
{
listBox.Items.Add(SelectAllText);
foreach (DataRow dr in dt.Rows)
{
listBox.Items.Add(dr[tableStyleInfo.DisplayMember]);
}
}
}
else
{
DataTable dtItems = tableStyleInfo.DataSource as DataTable;
if (dtItems != null)
{
listBox.Items.Add(SelectAllText);
foreach (DataRow dr in dtItems.Rows)
{
listBox.Items.Add(dr[tableStyleInfo.DisplayMember]);
}
}
}
}
}