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

Error when building custom RadFilterDataFieldEditor

20 Answers 485 Views
Filter
This is a migrated thread and some comments may be shown as answers.
PeterVV
Top achievements
Rank 1
PeterVV asked on 18 Mar 2010, 04:05 PM

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


20 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 22 Mar 2010, 05:36 PM
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.
0
Marc Hägele
Top achievements
Rank 1
answered on 21 May 2010, 10:54 AM
Is there any new improvements already done?
Trying to do the same...dropdowns in the Filtereditor.

Regards
Marc
0
Nikolay Rusev
Telerik team
answered on 25 May 2010, 04:08 PM
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.
0
michaelitrn
Top achievements
Rank 1
answered on 20 Jul 2010, 01:51 AM

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

 

 

0
mike
Top achievements
Rank 1
answered on 21 Jul 2010, 09:16 PM
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

0
michaelitrn
Top achievements
Rank 1
answered on 22 Jul 2010, 02:18 AM
Mike - I can confirm it is an issue. I'll kick it around a bit and see if I can figure it out.

Michael
0
Nikolay Rusev
Telerik team
answered on 22 Jul 2010, 02:33 PM
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
0
mike
Top achievements
Rank 1
answered on 22 Jul 2010, 03:08 PM
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
0
Nikolay Rusev
Telerik team
answered on 23 Jul 2010, 03:41 PM
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
0
mike
Top achievements
Rank 1
answered on 23 Jul 2010, 05:06 PM
Thanks.  That fixes it.
0
michaelitrn
Top achievements
Rank 1
answered on 27 Jul 2010, 03:27 AM
Nikolay,

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

0
Anne
Top achievements
Rank 1
answered on 27 Jul 2010, 09:06 AM
Can you translate the new 'SetEditorValues' in vb, please ?

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

Anne
0
Nikolay Rusev
Telerik team
answered on 29 Jul 2010, 04:09 PM
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
0
Anne
Top achievements
Rank 1
answered on 03 Aug 2010, 10:44 AM

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
0
Nikolay Rusev
Telerik team
answered on 06 Aug 2010, 09:31 AM
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
0
Steve McManamam
Top achievements
Rank 1
answered on 09 Dec 2010, 10:45 PM
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
0
Christian Burnaccioni
Top achievements
Rank 1
answered on 10 Dec 2010, 08:53 PM
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... :)
0
jelling
Top achievements
Rank 1
answered on 11 Jan 2011, 09:43 PM

0
Bryan Alfaro
Top achievements
Rank 1
answered on 19 Jan 2011, 07:44 PM
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;
    }
0
Steve McManamam
Top achievements
Rank 1
answered on 19 Jan 2011, 07:52 PM
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;
   }
Tags
Filter
Asked by
PeterVV
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Marc Hägele
Top achievements
Rank 1
michaelitrn
Top achievements
Rank 1
mike
Top achievements
Rank 1
Anne
Top achievements
Rank 1
Steve McManamam
Top achievements
Rank 1
Christian Burnaccioni
Top achievements
Rank 1
jelling
Top achievements
Rank 1
Bryan Alfaro
Top achievements
Rank 1
Share this question
or