IngoB
IngoB

Reputation: 2989

Infragistics XamGrid: How to prevent column filter from showing time?

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.

Upvotes: 0

Views: 231

Answers (1)

IngoB
IngoB

Reputation: 2989

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);
            }
        }
    }
}

Upvotes: 0

Related Questions