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

InvalidCastException when filtering

2 Answers 59 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
Joe
Top achievements
Rank 2
Joe asked on 11 Apr 2013, 12:12 AM
I am getting an InvalidCastException when there are 2 different classes at the same level of the tree hierarchy. For example, I have an MvDirectory class and an MvFile class. They both implement an int property called Size. They also share a common interface that implements Size. If I have a level of the hierarchy that consists of only MvDirectory instances, the filtering works fine. As soon as I add an instance of MvFile to the same level, I get an exception saying that MvFile cannot be cast to MvDirectory. I'm not sure why it is assuming all nodes at the same level are of the same type. Is there some way of getting it to use the shared interface or am I going to have to populate my tree with instances of the same class? Or am I just missing something?

Thanks,
Joe

2 Answers, 1 is accepted

Sort by
0
Yordanka
Telerik team
answered on 11 Apr 2013, 12:15 PM
Hello Joe,

Generally, this scenario is not supported and we cannot do much. We suggest you to move all logic to the base class and to work with it.
 
Kind regards,
Yordanka
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Joe
Top achievements
Rank 2
answered on 11 Apr 2013, 01:51 PM
Ok, thanks. The classes share an interface but not a common base class. I'll probably put them in some kind of wrapper, then.
Tags
TreeListView
Asked by
Joe
Top achievements
Rank 2
Answers by
Yordanka
Telerik team
Joe
Top achievements
Rank 2
Share this question
or