Casting issue for custom typed value in custom fieldeditor

3 posts, 0 answers
  1. Alex
    Alex avatar
    43 posts
    Member since:
    Jun 2011

    Posted 04 May 2017 Link to this post

    Hello, I am using a custom field editor that has a strongly type class value.  When I try to retrieve the value, the casing fails.

     

    public override System.Collections.ArrayList ExtractValues()
    {
        ArrayList list = new ArrayList();
     
        MyData = new FilterElement();
        MyData.Param = "kowkowkow";
        list.Add(MyData);
     
        return list;
    }

     

    FilterElement condition = ((Telerik.Web.UI.RadFilterEqualToFilterExpression<FilterElement>)((Telerik.Web.UI.RadFilterSingleExpressionItem)e.ExpressionItem).Expression).Value;

     

    FilterElement needed to implement IConvertible, so it does.  But I don't have any idea why it would need to or even try converting the class to a string.

     

    Error message is: Unable to cast object of type 'Telerik.Web.UI.RadFilterEqualToFilterExpression`1[System.String]' to type 'Telerik.Web.UI.RadFilterEqualToFilterExpression`1[FilterElement]'

     

    Any suggestions would be great.  Thanks!

  2. Alex
    Alex avatar
    43 posts
    Member since:
    Jun 2011

    Posted 04 May 2017 Link to this post

    This may be related:

    CustomFilterGenericEditor fieldEditor = new CustomFilterGenericEditor();
     
    filterConditions2.FieldEditors.Add(fieldEditor);
     
    fieldEditor.DisplayName = " ";
    fieldEditor.FieldName = "x123";
    fieldEditor.DataType = typeof(string);

     

    Changing the DataType to "typeof(FilterElement)"causes a new error:Object reference not set to an instance of an object.]
       Telerik.Web.UI.RadFilter.AddChildExpression(RadFilterGroupExpression group, Boolean isGroup).  Not sure how to debug wherever this is occurring.

     

  3. Rumen
    Admin
    Rumen avatar
    13302 posts

    Posted 10 May 2017 Link to this post

    Hi Alex,

    Can you explain in more details your scenario and what you are trying to achieve?

    As far as we can see you are trying to cast .Value to <FilterElement>, i.e.

    ((Telerik.Web.UI.RadFilterEqualToFilterExpression<FilterElement>)((Telerik.Web.UI.RadFilterSingleExpressionItem)e.ExpressionItem).Expression).Value 

    and you are getting the following error: "Unable to cast object of type..."

    Since you have implemented IConvertible, is it true that you have an implementation for FilterElement to String conversion? If you have a custom class, create a constructor which accepts a string and use the code as follows:

    FilterElement condition  = new FilterElement (Value);

    As to your second question about the string: when the filterExpression is build, it is a string in order to be sent to the SQL server as a string.

    Best regards,
    Rumen
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top