This is a migrated thread and some comments may be shown as answers.

Filter Empty Date Value

5 Answers 306 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Betsy
Top achievements
Rank 1
Betsy asked on 12 Nov 2010, 04:15 PM

 I have a GridView with a Nullable(DateTime) column (Inactive Date).  I want the grid to open with a default filter of records where the InactiveDate has no value.  How can I do this?  I have tried something like below but keep getting an error that String cannot be converted to a DateTime value.  I've tried Value="", Value=" ", Value="Nothing"....can't get it to work.

<telerik:RadGridView ItemsSource="{Binding Items}" AutoGenerateColumns="False" Name="datagrid" DataLoaded="datagrid_DataLoaded" >
  <telerik:RadGridView.FilterDescriptors>
    <telerik:FilterDescriptor Member="InActiveDate" Operator="IsEqualTo" Value=" " />
  </telerik:RadGridView.FilterDescriptors>
  <telerik:RadGridView.Columns>
    <telerik:GridViewDataColumn Header="Device Number" DataMemberBinding="{Binding DeviceNumber}" ShowDistinctFilters="False" />
    <telerik:GridViewDataColumn Header="Active Date" DataMemberBinding="{Binding ActiveDate}" DataFormatString="{}{0:d}" Width="90" />
    <telerik:GridViewDataColumn Header="InActive Date" DataMemberBinding="{Binding InActiveDate}" ShowDistinctFilters="False"  DataFormatString="{}{0:d}" Width="90"/>
    <telerik:GridViewDataColumn Header="Service Account" DataMemberBinding="{Binding IssuingAccountName}" />
    <telerik:GridViewDataColumn Header="License Plate" DataMemberBinding="{Binding VehicleLicensePlate,TargetNullValue=Not Assigned}" ShowDistinctFilters="False" />
    <telerik:GridViewDataColumn Header="Truck Number" DataMemberBinding="{Binding VehicleDisplayName}" ShowDistinctFilters="False"  />
  </telerik:RadGridView.Columns>
</telerik:RadGridView>

5 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 12 Nov 2010, 05:18 PM
Hello Heather,

You can try the following:

<telerik:FilterDescriptor Member="InActiveDate" Operator="IsEqualTo" Value="{x:Null}" />


Kind regards,
Veselin Vasilev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Betsy
Top achievements
Rank 1
answered on 12 Nov 2010, 05:41 PM
Wonderful, thank you.  Is there any way to make the Filter icon show that it has a filter?
0
Veselin Vasilev
Telerik team
answered on 17 Nov 2010, 05:02 PM
Hello Heather,

To make that work you need to use the ColumnFilterDescriptor. It should be created in code behind only.

Hope this helps.

Best wishes,
Veselin Vasilev
the Telerik team
See What's New in RadControls for WPF in Q3 2010 on Tuesday, November 16, 2010 11:00 AM - 12:00 PM EST or 10:00 PM - 11:00 PM EST: Register here>>
0
Betsy
Top achievements
Rank 1
answered on 23 Nov 2010, 09:10 PM
OK, so I changed things to create the filter in code as follows in the UserControl loaded event.

Dim columnDescriptor As New ColumnFilterDescriptor(DirectCast(vehiclegrid.Columns("InActiveDate"), IDataFieldDescriptor))
columnDescriptor.FieldFilter.Filter1.Operator = FilterOperator.IsEqualTo
columnDescriptor.FieldFilter.Filter1.Value = Nothing
vehiclegrid.FilterDescriptors.Add(columnDescriptor)

This works great but if I try to change the filter from the UI I get the following error and the filter does not change.  The InActiveDate column is of type Nullable(Of DateTime)
System.Windows.Data Error: 23 : Cannot convert '' from type 'FilterDescriptorUnsetValue' to type 'System.Nullable`1[System.DateTime]' for 'en-US' culture with default conversions; consider using Converter property of Binding. NotSupportedException:'System.NotSupportedException: DateTimeConverter cannot convert from Telerik.Windows.Data.FilterDescriptor+FilterDescriptorUnsetValue.
   at System.ComponentModel.TypeConverter.GetConvertFromException(Object value)
   at System.ComponentModel.TypeConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
   at System.ComponentModel.DateTimeConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
   at System.ComponentModel.NullableConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
   at MS.Internal.Data.DefaultValueConverter.ConvertHelper(Object o, Type destinationType, DependencyObject targetElement, CultureInfo culture, Boolean isForward)'
0
Veselin Vasilev
Telerik team
answered on 24 Nov 2010, 10:03 AM
Hello Heather,

I tried to reproduce the problem in a simple project but everything worked as expected - no exception was thrown. Can you please open a support ticket and attach a sample project there so we can investigate it more thoroughly.

Regards,
Veselin Vasilev
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
Tags
GridView
Asked by
Betsy
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Betsy
Top achievements
Rank 1
Share this question
or