473,385 Members | 1,912 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Tree view node selection error

Hi,

I have the code below that I'm using in a tree view to detect what node the
user has clicked on.

It compiles but on runtime I get a type cast error.

I've used this method for both the tool bar and menu and it works fine
extending the "handles" property inherent within .net.

Isn't the type supposed to be "TreeNode"?

Private Sub tvSelectFolder_NodeMouseClick(ByVal sender As Object, ByVal e As
System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles
tvSelectFolder.NodeMouseClick

'Declare an object of type TreeNode

Dim pTreeViewNode As TreeNode

'Now let's find out which tree view node was clicked

pTreeViewNode = CType(sender, TreeNode)

'Each item corresponds to a different feature

Select Case pTreeViewNode.Name

'//Exit the program

Case "InboxNode"

End Select

End Sub

End Class

Thanks,

Adam
Apr 10 '06 #1
3 1259
Adam,

Did you set (as would be done as first if you have a casting problem) set in
top of your program or in the options: Option Strict On

That helps mostly to find casting errors.

Cor

"Adam Honek" <Ad*******@Webmaster2001.freeserve.co.uk> schreef in bericht
news:%2******************@TK2MSFTNGP03.phx.gbl...
Hi,

I have the code below that I'm using in a tree view to detect what node
the user has clicked on.

It compiles but on runtime I get a type cast error.

I've used this method for both the tool bar and menu and it works fine
extending the "handles" property inherent within .net.

Isn't the type supposed to be "TreeNode"?

Private Sub tvSelectFolder_NodeMouseClick(ByVal sender As Object, ByVal e
As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles
tvSelectFolder.NodeMouseClick

'Declare an object of type TreeNode

Dim pTreeViewNode As TreeNode

'Now let's find out which tree view node was clicked

pTreeViewNode = CType(sender, TreeNode)

'Each item corresponds to a different feature

Select Case pTreeViewNode.Name

'//Exit the program

Case "InboxNode"

End Select

End Sub

End Class

Thanks,

Adam

Apr 11 '06 #2
I would guess that the sender argument is actually the TreeView itself
Use e.Node to get the clicked node

/claes

"Adam Honek" <Ad*******@Webmaster2001.freeserve.co.uk> wrote in message
news:%2******************@TK2MSFTNGP03.phx.gbl...
Hi,

I have the code below that I'm using in a tree view to detect what node
the user has clicked on.

It compiles but on runtime I get a type cast error.

I've used this method for both the tool bar and menu and it works fine
extending the "handles" property inherent within .net.

Isn't the type supposed to be "TreeNode"?

Private Sub tvSelectFolder_NodeMouseClick(ByVal sender As Object, ByVal e
As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles
tvSelectFolder.NodeMouseClick

'Declare an object of type TreeNode

Dim pTreeViewNode As TreeNode

'Now let's find out which tree view node was clicked

pTreeViewNode = CType(sender, TreeNode)

'Each item corresponds to a different feature

Select Case pTreeViewNode.Name

'//Exit the program

Case "InboxNode"

End Select

End Sub

End Class

Thanks,

Adam

Apr 11 '06 #3
Thanks, this does the trick using the "e" argument.

BTW, Option Strict was off.

Adam

"Claes Bergefall" <lo*****@nospam.nospam> wrote in message
news:OD**************@TK2MSFTNGP03.phx.gbl...
I would guess that the sender argument is actually the TreeView itself
Use e.Node to get the clicked node

/claes

"Adam Honek" <Ad*******@Webmaster2001.freeserve.co.uk> wrote in message
news:%2******************@TK2MSFTNGP03.phx.gbl...
Hi,

I have the code below that I'm using in a tree view to detect what node
the user has clicked on.

It compiles but on runtime I get a type cast error.

I've used this method for both the tool bar and menu and it works fine
extending the "handles" property inherent within .net.

Isn't the type supposed to be "TreeNode"?

Private Sub tvSelectFolder_NodeMouseClick(ByVal sender As Object, ByVal e
As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles
tvSelectFolder.NodeMouseClick

'Declare an object of type TreeNode

Dim pTreeViewNode As TreeNode

'Now let's find out which tree view node was clicked

pTreeViewNode = CType(sender, TreeNode)

'Each item corresponds to a different feature

Select Case pTreeViewNode.Name

'//Exit the program

Case "InboxNode"

End Select

End Sub

End Class

Thanks,

Adam


Apr 11 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Steve Johnson | last post by:
Been banging my head on this for two days now. Hope someone can help! My test program below is in the form of a single JSP, with a Node class build in. (All the coded needed to run is below.) ...
0
by: Tree menu using XML | last post by:
I have one XML file that has nodes and sub node and each and every node has the attribute call visible if its value is true then diplay this node else don't display thid node, but this condition i...
4
by: ghanley | last post by:
Hi Guys, I need some help with a problem related to the looping through a recordset to display on a tree view control. My table has no Primary key - because duplicates are allowed. ID ...
3
by: Saradhi | last post by:
Hi All, Here I am facing a performance problem with the TreeView Node renaming. I am displaying a hierarchy Data in a treeview in my Windows C# Application. My tree view represents an...
1
by: JN | last post by:
Hi All, I have a tree view which has parent nodes of each letter of the alphabet. The root node will be the customers name that relate to the parent node letter. I also have a gridview which is...
2
by: Jerry Langley | last post by:
Once a treeview node is selected how can I programmatically unselect it so that it might be selected again following the first selection if the user desires? The after selection event only fires...
2
by: dave.dolan | last post by:
I have generated a nice tree view that displays some otherwise cyptic XML in an easy to follow manner. The trouble is that the TreeView assumes that I'm wanting a link in each of the nodes, and I...
7
by: Adam Honek | last post by:
Hi all, How do we select a tree view's node outside of a tree view event? Looking through the lists there's no select function, the nearest I can find is GetNodeAt but this seems to want the...
0
by: Rohit111111 | last post by:
Hello all, I have a tree view control that will populate data upto n level,on selection of a node i am binding a datagrid on the same page,now i have to expand that node which i have selected,which...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.