DateFilterDescriptor DateTime?

6 posts, 0 answers
  1. Daniel
    Daniel avatar
    19 posts
    Member since:
    Nov 2010

    Posted 17 May 2012 Link to this post

    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
  2. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 22 May 2012 Link to this post

    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 >>
  3. Daniel
    Daniel avatar
    19 posts
    Member since:
    Nov 2010

    Posted 22 May 2012 Link to this post

    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

  4. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 28 May 2012 Link to this post

    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 >>
  5. Azib
    Azib avatar
    7 posts
    Member since:
    Jun 2012

    Posted 20 Jun 2012 Link to this post

    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
  6. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 22 Jun 2012 Link to this post

    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 >>
Back to Top