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

Casting issue for custom typed value in custom fieldeditor

2 Answers 18 Views
Filter
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 04 May 2017, 05:43 PM

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 Answers, 1 is accepted

Sort by
0
Alex
Top achievements
Rank 1
answered on 04 May 2017, 07:10 PM

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.

 

0
Rumen
Telerik team
answered on 10 May 2017, 10:44 AM
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.
Tags
Filter
Asked by
Alex
Top achievements
Rank 1
Answers by
Alex
Top achievements
Rank 1
Rumen
Telerik team
Share this question
or