Hi im coming to the end of a project that's a file management program that works with images and im getting some very strange errors. In my program im used a subclassed treeview and subclassed tree nodes. Everything has been working great with the new classes until today when just one of them has stopped working.
The process is you click a button from a toolstrip and the subclassed treeview gathers up some image files and displays them using my subclassed treenodes. The if the user clicks on one of the nodes that displays the image files the action is picked up by the treeviews 'AfterSelect' event and then passed onto a picture box for display. But for some reason today ive been getting an System.InvalidCastException from the custom treenode in 'AfterSelect'. This is odd because theres lots of methods that are using the same subclassed tree nodes without any error and up until today the code in 'AfterSelect' has been working fine. So to hunt down the problem i rebuilt the subclassed treeview based around a small bit of example code from Microsoft . I tested it out on a different form and it worked fine. I then moved it over to my main form and tested it there but with a standard button to trigger the sequence rather than from the tool strip i want to use. It worked fine there as well. So then i took the code from the standard button and attached it to the toolstrip button and i got the System.InvalidCastException again. I even tried adding a different button to the toolstrip and triggering the sequence from there and it still gives the same error.
Code:
Private Sub SourceToolStripAdd_Click(sender As Object, e As EventArgs) Handles SourceToolStripAdd.Click
XTreeView1.Grab_Some_files()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
XTreeView1.Grab_Some_files()
End Sub
Private Sub XTreeView1_AfterSelect(sender As Object, e As TreeViewEventArgs) Handles XTreeView1.AfterSelect
Dim mynode As xNodeInput
mynode = CType(e.Node, xNodeInput)
MessageBox.Show("Node selected is " & mynode.nxText_SourceFile)
End Sub
I added the line
in the 'public sub new' on the subclassed treenode as Microsoft suggested but it has not helped
I cant think what might cause this.