0

We are using DateTime columns with time, but need the (excel style distinct elements) column filter to show only the dates, without time. Is that possible?

I found an article at Infragistics which describes how to add a custom filter but not how to change an existing one.

IngoB
  • 2,552
  • 1
  • 20
  • 35

1 Answers1

0

Got the following code snipped from infragistics support (thanks Tacho!):

private void XamDataGrid_RecordFilterDropDownOpening(object sender, RecordFilterDropDownOpeningEventArgs e)
{
    if (e.Field.DataType == typeof(DateTime))
    {
        List<FilterDropDownItem> cellValues = e.DropDownItems.Where(i => i.IsCellValue).ToList();
        foreach (FilterDropDownItem item in cellValues)
            e.DropDownItems.Remove(item);


        foreach (FilterDropDownItem item in cellValues)
        {
            item.DisplayText = (item.Value as DateTime?).Value.ToString("yyyy/MM/dd");
            if (!e.DropDownItems.Contains(e.DropDownItems.FirstOrDefault(i => i.DisplayText == item.DisplayText)))
            {
                var newItem = new FilterDropDownItem(new Infragistics.Windows.Controls.ComparisonCondition(
                    Infragistics.Windows.Controls.ComparisonOperator.Contains, item.DisplayText), item.DisplayText);
                e.DropDownItems.Add(newItem);
            }
        }
    }
}
IngoB
  • 2,552
  • 1
  • 20
  • 35