Error when building custom RadFilterDataFieldEditor

21 posts, 0 answers
  1. PeterVV
    PeterVV avatar
    7 posts
    Member since:
    Jul 2006

    Posted 18 Mar 2010 Link to this post

    When creating an custom DataFieldEditor an error is thrown upon postback.
    The custom class looks like (same implementation as the RadFilterTextFieldEditor)

    Public Class RadFilterMyTextFieldEditor  
        Inherits RadFilterDataFieldEditor  
     
        Protected Overrides Sub CopySettings(ByVal baseEditor As RadFilterDataFieldEditor)  
            MyBase.CopySettings(baseEditor)  
            Dim editor As RadFilterTextFieldEditor = TryCast(baseEditor, RadFilterTextFieldEditor)  
            If (Not editor Is Nothing) Then  
                Me.TextBoxWidth = editor.TextBoxWidth  
            End If  
        End Sub  
     
        Public Overrides Function ExtractValues() As ArrayList  
            Dim list As New ArrayList  
            list.Add(Me._textBoxControl.Text)  
            If Not MyBase.IsSingleValue Then  
                list.Add(Me._secondTextBoxControl.Text)  
            End If  
            Return list  
        End Function  
     
        Public Overrides Sub InitializeEditor(ByVal container As Control)  
            Me._textBoxControl = New TextBox  
            Me._textBoxControl.CssClass = "rfText" 
            Me._textBoxControl.Width = Unit.Pixel(Me.TextBoxWidth)  
            container.Controls.Add(Me._textBoxControl)  
            If Not MyBase.IsSingleValue Then  
                MyBase.AddBetweenDelimeterControl(container)  
                Me._secondTextBoxControl = New TextBox  
                Me._secondTextBoxControl.CssClass = ("rfText")  
                Me._secondTextBoxControl.Width = Unit.Pixel(Me.TextBoxWidth)  
                container.Controls.Add(Me._secondTextBoxControl)  
            End If  
        End Sub  
     
        Public Overrides Sub SetEditorValues(ByVal values As ArrayList)  
            If (Not values Is Nothing) Then  
                If (Not values.Item(0) Is Nothing) Then  
                    Me._textBoxControl.Text = (values.Item(0).ToString)  
                End If  
                If (Not MyBase.IsSingleValue AndAlso (Not values.Item(1) Is Nothing)) Then  
                    Me._secondTextBoxControl.Text = values.Item(1).ToString  
                End If  
            End If  
        End Sub  
     
        <DefaultValue("120"), NotifyParentProperty(True)> _  
        Public Property TextBoxWidth() As Integer  
            Get  
                Dim obj2 As Object = MyBase.ViewState.Item("TextBoxWidth")  
                If (obj2 Is Nothing) Then  
                    Return 120  
                End If  
                Return CInt(obj2)  
            End Get  
            Set(ByVal value As Integer)  
                MyBase.ViewState.Item("TextBoxWidth") = value  
            End Set  
        End Property  
     
        ' Fields  
        Private _secondTextBoxControl As TextBox  
        Private _textBoxControl As TextBox  
     
    End Class 

    When using this on a web form like

        Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init  
     
            Dim oMyTextFilter As New RadFilterMyTextFieldEditor  
            oMyTextFilter.FieldName = "Company" 
     
            RadFilter1.FieldEditors.Add(oMyTextFilter)  
     
        End Sub  
     

    The following error is thrown upon postback

    Exception Details: System.ArgumentNullException: Value cannot be null.  
    Parameter name: item  
     
    Source Error:   
     
    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.    
     
    Stack Trace:   
     
     
    [ArgumentNullException: Value cannot be null.  
    Parameter name: item]  
       Telerik.Web.UI.RadFilterDataFieldEditorCollection.InsertInternal(Int32 index, RadFilterDataFieldEditor item) +77  
       Telerik.Web.UI.RadFilterDataFieldEditorCollection.Add(RadFilterDataFieldEditor item) +40  
       Telerik.Web.UI.RadFilterDataFieldEditorCollection.System.Web.UI.IStateManager.LoadViewState(Object state) +602  
       Telerik.Web.UI.RadFilter.LoadViewState(Object savedState) +155  
       System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +183  
       System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState) +134  
       System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +221  
       System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState) +134  
       System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +221  
       System.Web.UI.Page.LoadAllState() +312  
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1661  
     
       
     

    What goes wrong?
    My intention is to create a custom editor with dropdown list boxes in stead of the regular text edits


  2. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2284 posts

    Posted 22 Mar 2010 Link to this post

    Hello Peter,

    I am afraid that this known limitation of RadFilter with the current release. In next internal build there will be available improvements in this direction. Support for custom field editor for RadFilter will be officially available for SP1 of RadControls for ASP.NET AJAX.

    All the best,
    Nikolay
    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Marc Hägele
    Marc Hägele avatar
    2 posts
    Member since:
    Dec 2009

    Posted 21 May 2010 Link to this post

    Is there any new improvements already done?
    Trying to do the same...dropdowns in the Filtereditor.

    Regards
    Marc
  5. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2284 posts

    Posted 25 May 2010 Link to this post

    Hello Marc,

    Yes we have added ability for creating custom field editors. For your convenience I've prepared sample application demonstrating how you can build custom editor that renders RadComboBox.

    All the best,
    Nikolay
    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.
  6. michaelitrn
    michaelitrn avatar
    7 posts
    Member since:
    Mar 2007

    Posted 19 Jul 2010 Link to this post

    Nikolay,

    I attempted to load the RadFilterDropDownEditor control dynamically to the RadFilter, instead of defining it at design time. The dropdownlist appears, but it is was not populated. I was able to resolve this issue be modifiying your custom editor. It appears to have been a viewstate issue, but I believe I have it working now. I have included the modified CustomEditors.cs file you created if anyone would like to use it and for your review. Now I'm off to implement and multi select custom filter editor that will result in a sql in clause when applied.

    Is the source code for RadFilterSqlQueryProvider available?

    Are more filter editors going to be released soon?

    Best Regards,

    Michael

     

     

    namespace CustomEditors
    {
        public class RadFilterDropDownEditor : RadFilterDataFieldEditor
        {
            protected override void CopySettings(RadFilterDataFieldEditor baseEditor)
            {
                base.CopySettings(baseEditor);
                var editor = baseEditor as RadFilterDropDownEditor;
                if (editor != null)
                {
                    DataSourceID = editor.DataSourceID;
                    DataTextField = editor.DataTextField;
                    DataValueField = editor.DataValueField;
                    DataSource = editor.DataSource;
                }
            }
      
            public override System.Collections.ArrayList ExtractValues()
            {
                ArrayList list = new ArrayList();
                list.Add(_combo.SelectedValue);
                return list;
            }
      
            public override void InitializeEditor(System.Web.UI.Control container)
            {
                _combo = new RadComboBox();
                _combo.ID = "MyCombo";
                _combo.DataTextField = DataTextField;
                _combo.DataValueField = DataValueField;
                if (string.IsNullOrEmpty(DataSourceID))
                {
                    _combo.DataSource = DataSource;
                    _combo.DataBind();
                }
                else
                {
                    _combo.DataSourceID = DataSourceID;
                }
                container.Controls.Add(_combo);
            }
      
            public override void SetEditorValues(System.Collections.ArrayList values)
            {
                if (values != null && values.Count > 0)
                {
                    if (values[0] == null)
                        return;
                    var item = _combo.FindItemByValue(values[0].ToString());
                    if (item != null)
                        item.Selected = true;
                }
            }
      
            public string DataTextField
            {
                get
                {
                    string ret = string.Empty;
                    if (this.ViewState["datatextfield"] != null)
                    {
                        ret = this.ViewState["datatextfield"].ToString();
                    }
                    return ret;
                }
                set
                {
                    this.ViewState["datatextfield"] = value;
                }
      
      
            }
            public string DataValueField
            {
                get
                {
                    string ret = string.Empty;
                    if (this.ViewState["DataValueField"] != null)
                    {
                        ret = this.ViewState["DataValueField"].ToString();
                    }
      
                    return ret;
                }
                set
                {
                    this.ViewState["DataValueField"] = value;
                }
      
      
            }
            public string DataSourceID
            {
                get
                {
                    string ret = string.Empty;
                    if (this.ViewState["DataSourceID"] != null)
                    {
                        ret = this.ViewState["DataSourceID"].ToString();
                    }
      
                    return ret;
                }
                set
                {
                    this.ViewState["DataSourceID"] = value;
                }
      
      
            }
            public Object DataSource
            {
                get
                {
                    Object ret = null;
                    if (this.ViewState["DataSource"] != null)
                    {
                        ret = this.ViewState["DataSource"];
                    }
      
                    return ret;
                }
                set
                {
                    this.ViewState["DataSource"] = value;
                }
      
      
            }
            private RadComboBox _combo;
        }
    }

     

     

  7. mike
    mike avatar
    6 posts
    Member since:
    Jan 2010

    Posted 21 Jul 2010 Link to this post

    I'm trying to implement a custom editor with dropdown as demonstrated in the sample project, radfiltercustomfield.zip.  The dropdown appears correctly, but I'm having an issue retaining the selected dropdown value.

    Here is the clickpath to recreate.

    1. Add Expression
    2. In the custom dropdown editor, select an item other then the first item
    3. Add a second expression and the selected value in the first dropdown resets

    Can anyone confirm there is an issue with the sample?  And also suggest a fix?

    Thank you.
    Mike

  8. michaelitrn
    michaelitrn avatar
    7 posts
    Member since:
    Mar 2007

    Posted 21 Jul 2010 Link to this post

    Mike - I can confirm it is an issue. I'll kick it around a bit and see if I can figure it out.

    Michael
  9. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2284 posts

    Posted 22 Jul 2010 Link to this post

    Hello Mike and Michael,

    For your convenience I am attaching sample application demonstrating creating custom editor on Page.Load event.

    Regards,
    Nikolay
    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
  10. mike
    mike avatar
    6 posts
    Member since:
    Jan 2010

    Posted 22 Jul 2010 Link to this post

    Nikolay,

    Thanks for your response.  While your radfiltercustomruntimeeditor.zip sample does demonstrate how to add custom editors in the Page.Load event, that wasn't my issue.

    If you follow the clickpath I previously provided, I think you will see the same issue with selected dropdown values being reset.  The same issue exists with both the original radfiltercustomfield.zip sample and the radfiltercustomruntimeeditor.zip sample.

    1. Add Expression
    2. In the custom dropdown editor, select an item other then the first item
    3. Add a second expression and the selected value in the first dropdown resets

    From my debugging I see that when SetEditorValues is being called, the selected values[0] is correct, but the _combo doesn't have any items, so the selection doesn't occur.

    Thanks again.
    Mike
  11. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2284 posts

    Posted 23 Jul 2010 Link to this post

    Hello Mike,

    Indeed you are right. I didn't notice that behavior. Changing SetEditorValues as bellow should do the trick

    01.public override void SetEditorValues(System.Collections.ArrayList values)
    02.        {
    03.            if (values != null && values.Count > 0)
    04.            {
    05.                if (values[0] == null)
    06.                    return;
    07.                _combo.DataBound += (sender, args) =>
    08.                    {
    09.                        var item = _combo.FindItemByValue(values[0].ToString());
    10.                        if (item != null)
    11.                            item.Selected = true;
    12.                    };
    13.            }
    14.        }


    All the best,
    Nikolay
    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
  12. mike
    mike avatar
    6 posts
    Member since:
    Jan 2010

    Posted 23 Jul 2010 Link to this post

    Thanks.  That fixes it.
  13. michaelitrn
    michaelitrn avatar
    7 posts
    Member since:
    Mar 2007

    Posted 26 Jul 2010 Link to this post

    Nikolay,

    Is the source code for RadFilterSqlQueryProvider available?
    Are more filter editors going to be released soon?

  14. Anne
    Anne avatar
    39 posts
    Member since:
    May 2010

    Posted 27 Jul 2010 Link to this post

    Can you translate the new 'SetEditorValues' in vb, please ?

    I don't find _combo.DataBound....

    Anne
  15. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2284 posts

    Posted 29 Jul 2010 Link to this post

    Hello Anne,

    @Michael: Yes the code for RadFilterSqlQueryProvider as for any other of RadControls for ASP.NET AJAX is available in the control suite. Currently we do not have any plans for introduction other editors for RadFilter.

    @Anne-Christine: DataBound is just an event handler. You can try http://converter.telerik.com/ or any other C# to VB converters.

    All the best,
    Nikolay
    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
  16. Anne
    Anne avatar
    39 posts
    Member since:
    May 2010

    Posted 03 Aug 2010 Link to this post

    Hello Nikolay,

    I don't know how translate

     _combo.DataBound += (sender, args) =>

    Converter give

    _combo.DataBound += Function(sender, args) Do

    But it isn't recognize by vs2008

     


    Anne
  17. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2284 posts

    Posted 06 Aug 2010 Link to this post

    Hello Anne,

    You can change the code by simply handling RadComboBox DataBound event and copy-paste the body into the handler.
    http://msdn.microsoft.com/en-us/library/6yyk8z93%28VS.71%29.aspx

    Best wishes,
    Nikolay
    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
  18. Steve McManamam
    Steve McManamam avatar
    2 posts
    Member since:
    May 2010

    Posted 09 Dec 2010 Link to this post

    There is still an issue when using the BETWEEN or NOT BETWEEN function,
    The control does not create two instances and no expression gets pulled out..

    Any ideas?

    Thanks,
    Ata
  19. Christian Burnaccioni
    Christian Burnaccioni avatar
    1 posts
    Member since:
    Jun 2010

    Posted 10 Dec 2010 Link to this post

    Using base.IsSingleValue fixed the problem, just created two RadComboBoxes and instantiate the second one only when IsSingleValue == false and add it to the container... :)
  20. jelling
    jelling avatar
    13 posts
    Member since:
    Aug 2006

    Posted 11 Jan 2011 Link to this post


  21. Bryan Alfaro
    Bryan Alfaro avatar
    5 posts
    Member since:
    Dec 2009

    Posted 19 Jan 2011 Link to this post

    Christian,

    Can you post your code for the BETWEEN and NOT BETWEEN code?  I also used base.IsSingleValue and then creating a second combobox.  My problem appears to be that the values chosen by thte user never get extracted.  The values collection always shows two entries but they never get set to the proper values.  They are always 0.

    Thanks,
    Bryan

     

    public class RadFilterDropDownEditor : RadFilterDataFieldEditor
        {
            public RadFilterDropDownEditor()
            {
      
            }
      
            protected override void CopySettings(RadFilterDataFieldEditor baseEditor)
            {
                base.CopySettings(baseEditor);
                var editor = baseEditor as RadFilterDropDownEditor;
                if (editor != null)
                {
                    DataSourceID = editor.DataSourceID;
                    DataTextField = editor.DataTextField;
                    DataValueField = editor.DataValueField;
                }
            }
      
            public override System.Collections.ArrayList ExtractValues()
            {
                ArrayList list = new ArrayList();
                list.Add(_firstCombo.SelectedValue);
                if (!IsSingleValue != null)
                {
                    list.Add(_secondCombo.SelectedValue);
                }
                return list;
            }
      
            public override void InitializeEditor(System.Web.UI.Control container)
            {
                _firstCombo = new RadComboBox();
                _firstCombo.ID = "_firstCombo";
                _firstCombo.DataTextField = DataTextField;
                _firstCombo.DataValueField = DataValueField;
                _firstCombo.DataSourceID = DataSourceID;
                container.Controls.Add(_firstCombo);
      
                if (!IsSingleValue)
                {
                    AddBetweenDelimeterControl(container);
                    _secondCombo = new RadComboBox();
                    _secondCombo.ID = "_secondCombo";
                    _secondCombo.DataTextField = DataTextField;
                    _secondCombo.DataValueField = DataValueField;
                    _secondCombo.DataSourceID = DataSourceID;
                    container.Controls.Add(_secondCombo);
                }
            }
      
            public override void SetEditorValues(System.Collections.ArrayList values)
            {
                if (values != null)
                
                    if(values[0] != null)
                    {
                        _firstCombo.DataBound += (sender, args) =>
                        {
                            var item = _firstCombo.FindItemByValue(values[0].ToString());
                            if (item != null)
                                item.Selected = true;
                        };
                    }
      
                    if (!IsSingleValue)
                    {
                        if (values[1] != null)
                        {
                            _secondCombo.DataBound += (sender, args) =>
                            {
                                var item = _secondCombo.FindItemByValue(values[1].ToString());
                                if (item != null)
                                    item.Selected = true;
                            };
                        }
                    }
                }
            }
      
            public string DataTextField { get; set; }
            public string DataValueField { get; set; }
            public string DataSourceID { get; set; }
      
            private RadComboBox _firstCombo;
            private RadComboBox _secondCombo;
        }
  22. Steve McManamam
    Steve McManamam avatar
    2 posts
    Member since:
    May 2010

    Posted 19 Jan 2011 Link to this post

    I actually have two accounts on Telerik :P :P
    You were really close there,
    I modified my code to view two textboxes for between statements and one combo for others. But the logic is the same I'm sure you can figure it out. Heres the code

    public class RadFilterDropDownEditor : RadFilterDataFieldEditor
       {
     
           protected override void CopySettings(RadFilterDataFieldEditor baseEditor)
           {
               base.CopySettings(baseEditor);
               var editor = baseEditor as RadFilterDropDownEditor;
               if (editor != null)
               {
                   base.BetweenDelimeterText = "AND";
                   DataSourceID = editor.DataSourceID;
                   DataTextField = editor.DataTextField;
                   DataValueField = editor.DataValueField;
                   values = editor.values;
               }
           }
     
           public override System.Collections.ArrayList ExtractValues()
           {
               ArrayList list = new ArrayList();
               if (base.IsSingleValue)
               {
                   list.Add(_combo.Text);
               }
               else
               {
                   list.Add(_text1.Text);
                   list.Add(_text2.Text);
               }
               return list;
           }
     
           public override void InitializeEditor(System.Web.UI.Control container)
           {
               if (base.IsSingleValue)
               {
                   _combo = new RadComboBox();
                   _combo.ID = "MyCombo";
                   _combo.DataTextField = DataTextField;
                   _combo.DataValueField = DataValueField;
                   _combo.DataSourceID = DataSourceID;
                   _combo.AllowCustomText = true;
                   _combo.MaxHeight = 400;
                   _combo.Width = 200;
                   _combo.Items.Clear();
                   foreach (string value in values)
                   {
                       _combo.Items.Add(new RadComboBoxItem(value));
                   }
     
                   container.Controls.Add(_combo);
               }
               else
               {
                   _text1 = new RadTextBox();
                   _text1.ID = "MyText";
                   _text1.Width = 50;
                   container.Controls.Add(_text1);
                   base.AddBetweenDelimeterControl(container);
                   _text2 = new RadTextBox();
                   _text2.ID = "MyText2";
                   _text2.Width = 50;
                   container.Controls.Add(_text2);
               }
     
                
           }
     
     
           public override void SetEditorValues(System.Collections.ArrayList values)
           {
               /*
               if (values != null && values.Count > 0)
               {
                   if (values[0] == null)
                       return;
                   var item = _combo.FindItemByValue(values[0].ToString());
                   if (item != null)
                       item.Selected = true;
               }
                */
               if (values[0] == null)
                   return;
     
               if (base.IsSingleValue)
               {
                   _combo.Text = values[0].ToString();
               }
               else
               {
                   _text1.Text = values[0].ToString();
                   _text2.Text = values[1].ToString();
               }
     
           }
     
           public string DataTextField
           {
               get
               {
                   return (string)ViewState["DataTextField"] ?? string.Empty;
               }
               set
               {
                   ViewState["DataTextField"] = value;
               }
           }
     
           public List<string> values
           {
               get
               {
                   return (List<string>)ViewState["values"];
               }
               set
               {
                   ViewState["values"] = value;
               }
           }
     
           public string DataValueField
           {
               get
               {
                   return (string)ViewState["DataValueField"] ?? string.Empty;
               }
               set
               {
                   ViewState["DataValueField"] = value;
               }
           }
           public string DataSourceID
           {
               get
               {
                   return (string)ViewState["DataSourceID"] ?? string.Empty;
               }
               set
               {
                   ViewState["DataSourceID"] = value;
               }
           }
     
           private RadComboBox _combo;
           private RadTextBox _text1;
           private RadTextBox _text2;
       }
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017