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

DateFilterDescriptor DateTime?

5 Answers 224 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 17 May 2012, 04:43 PM

Hi

How can I filter radGridView (2012.1.321.40) with BindingList<IPresenceLog> on nullable DateTime field "SystemEnd" to get entries with

SystemEnd.Hasvalue=false?  Neither the simple FilterDescriptor nor the DateFilterDescriptor seems to work with any of the available FilterOperators.

//public class PresenceLogModel : PresenceLog, INotifyPropertyChanged, IValidatable
//public class PresenceLog : IPresenceLog
//private BindingList<IPresenceLog> _PresenceLogList = new BindingList<IPresenceLog>();
  
       private void BindDataSource()
        {
            if (radGridViewPZE.Columns.Count == 0)
            {
                radGridViewPZE.MasterTemplate.AutoGenerateColumns = false;
  
                radGridViewPZE.DataSource = _PresenceLogList;
  
                radGridViewPZE.Columns.Add(CommonFunctions.NewTextCol("ResourceNo", "Resource", 100, true));
                radGridViewPZE.Columns.Add(CommonFunctions.NewTextCol("ResourceName", "Resourcen Name", 120, true));
                radGridViewPZE.Columns.Add(CommonFunctions.NewDateTimeCol("SystemBegin", "Begin", 100, true));
                radGridViewPZE.Columns.Add(CommonFunctions.NewDateTimeColWithNull("SystemEnd", "Ende", 100, true));
  
            }
            else
                radGridViewPZE.DataSource = _PresenceLogList;
        }
  
  
         public static GridViewDateTimeColumn NewDateTimeCol(string fieldname, string title, int width, bool isvisible)
         {
             GridViewDateTimeColumn col = new GridViewDateTimeColumn(fieldname);
             col.Name = fieldname;
             col.HeaderText = title;
             col.Width = width;
             col.IsVisible = isvisible;
             col.DataType = typeof(DateTime);
             col.FormatString = "{0:dd.MM.yy HH:mm}";  //dd/MM/yyyy HH:mm
             return col;
         }
  
         public static GridViewDateTimeColumn NewDateTimeColWithNull(string fieldname, string title, int width, bool isvisible)
         {
             GridViewDateTimeColumn col = new GridViewDateTimeColumn(fieldname);
             col.Name = fieldname;
             col.HeaderText = title;
             col.Width = width;
             col.IsVisible = isvisible;
             col.DataType = typeof(System.Nullable<DateTime>);
             col.FormatString = "{0:dd.MM.yy HH:mm}";  //dd/MM/yyyy HH:mm
             return col;
         }
  
  
  
        private void cmbTBFilterOpenEntries_ToggleStateChanged(object sender, StateChangedEventArgs args)
        {
            if (cmbTBFilterOpenEntries.ToggleState == ToggleState.On)
            {
                if (resourceFilterOpenEntries == null)
                {
                    //resourceFilterOpenEntries = new DateFilterDescriptor("SystemEnd", FilterOperator.IsEqualTo, new DateTime?(),true);
                    resourceFilterOpenEntries = new DateFilterDescriptor();
                    resourceFilterOpenEntries.PropertyName = "SystemEnd";
                    resourceFilterOpenEntries.Operator = FilterOperator.IsNull; //FilterOperator.IsEqualTo
                    resourceFilterOpenEntries.Value = null;
                    //resourceFilterOpenEntries.IsFilterEditor = true;
                }
                this.radGridViewPZE.FilterDescriptors.Add(resourceFilterOpenEntries);
                if (!(radGridViewPZE.EnableFiltering)) 
                    radGridViewPZE.EnableFiltering = true;
            }
            else
            {
                this.radGridViewPZE.FilterDescriptors.Remove(resourceFilterOpenEntries);
            }
        }

Any suggestions?
Thanks Daniel

5 Answers, 1 is accepted

Sort by
0
Julian Benkov
Telerik team
answered on 22 May 2012, 02:23 PM
Hello Daniel,

Thank you for writing.

For this scenario you can use the IsNull operator of the FilterDescriptor to implement the desired behavior:
protected override void OnButton3Click()
{
    FilterDescriptor descriptor = new FilterDescriptor("YourColumnName", FilterOperator.IsNull, null);
    this.gridView.FilterDescriptors.Add(descriptor);
}

I hope this helps. Let me know if you need further assistance.

Greetings,
Julian Benkov
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Daniel
Top achievements
Rank 1
answered on 22 May 2012, 06:25 PM

Hi Julian

Not much difference to my sample, but its simply not working!

My Binding list uses Nullable DateTime Fields which are defined in an interface.

 DateTime? SystemEnd { get; set; }

But neither the Excel Like Filter nor the programatically set FilterDescriptor or DateFilterDescriptor work with IsNull
also tried with radGridView.MasterTemplate.AutoGenerateColumns = true instead of adding columns programatically but no difference,
and tried without RadGridLocalizationProvider butalso no difference.

In VS2010 Expressions looks correct:

?_resourceFilterOpenEntries.Expression
"SystemEnd IS NULL"

All other Filter types work, but not Null || Not Null Filters on DateTime? Fields
 

Anything else to try?

Regards
Daniel

0
Julian Benkov
Telerik team
answered on 28 May 2012, 12:41 PM
Hi Daniel,

Please accept my apologies for the delayed answer.

I made a test with the latest development version and the issue is already resolved there. The problem is valid for the 2012.1.321 version, which is used in your application. The upcoming Q2 2012 release scheduled for the first half of June will include a fix for this. I am not able to provide you with a workaround for the time being, due to the nature of the issue.

Your Telerik points have been updated for the feedback.

All the best,
Julian Benkov
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Azib
Top achievements
Rank 1
answered on 20 Jun 2012, 06:11 AM
Hello Julian

I am having the same problem. I tried to employ a TextBox for Search as mentioned in your GridView/Search demo. But upon running the project i get an error

Expression of type 'System.Nullable' 1[System.DateTime]' cannot be used for parameter of type 'System.Object' of method 'Boolean Equals (System.Object, System.Object)'

Even i tried using the same 'CustomFilterDescriptor.cs' and 'CustomFilterBehavior.cs' classes as in the demo but same error.

Please note that some of the properties bound are nullable, including DateTime? and int?

is there a way around employing this custom filter with Nullable DateTime and/or Int columns?

BTW, i am using ViewModel and bound RadGridView to the QSDCV in ViewModel.

Thanks
0
Julian Benkov
Telerik team
answered on 22 Jun 2012, 12:31 PM
Hello Azib,

Please send me a sample project that covers your scenario. I will try to reproduce the issue locally and find the best solution for the case.

Note that you should open a new support ticket in order to be able to attach your project.

Thank you for your cooperation. I am looking forward to your response.

All the best,
Julian Benkov
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
Tags
GridView
Asked by
Daniel
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
Daniel
Top achievements
Rank 1
Azib
Top achievements
Rank 1
Share this question
or