Nevron Forum

Invalid Cast Exception in NTreeList control

https://www.nevron.com/Forum/Topic5065.aspx

By Tomas Vera - Friday, April 8, 2011

Hello,
I am using a NTreeList control in detail view.
When I first populate the control, I am able to sort the columns as expected.
But if I add entries to my data source and rebuild the node collection, as soon as I click on any column header, I get an exception:

"An unhandled exception of type 'System.InvalidCastException' occurred in Nevron.Presentation.dll

Additional Information: Unable to cast object of type 'Nevron.UI.Winform.Controls.NTreeListNode' to type 'Nevron.UI.Winform.Controls.NTReeListHeaderItem'
"

Unfortunately, this error is holding up release of a product update (of course).

Any help/ideas are much appreciated!

-tomas
By Nevron Support - Friday, April 8, 2011

Hi Tomas,

Can you describe how do you add entries in your data source and rebuild the nodes collection?

Do you use NTreeListTableData to bind your data source to the NTreeList?

I am asking this to be able to reproduce the problem you got and find what cause it.



By lars knox - Monday, May 30, 2011

Hi,

I work with Tomas. Just wanted to post this solution in case anyone else needs it. If you use ".Nodes.Clear();" subsequent mouse clicking on the control will create the error mentioned above. The work-around was to use ".Nodes.RemoveAt(0);" (between SuspendLayout and ResumeLayout of course) until there are no more nodes in the tree. This will give a similar effect without causing subsequent errors.

Lars