Getting the selected value from a TreeView control

S

Swimminschrage

I'm having problems getting the currently selected node out of a TreeView
control.

I currently have:

Dim key As String
key = Mid(Me.treeBranches.SelectedItem.key, 0,
Len(Me.treeBranches.SelectedItem.key) - 2)

Me.description = key

where "treeBranches" is the name of my treeview control. I'm attempting to
get the key except for the last two characters, but I keep getting an
"Invalid procedure call or argument"

Thanks for the help

Andy
 
D

Dale Fye

Have you tried setting the start position to 1 rather than 0?

I would use Left( ) instead of Mid( ). You don't really need to rewrite the
whole thing the way I have done below, but this is probably more readable,
and addresses (although only mimimally) the case where the key is shorter
than you think it should be.

Dim key As String
key = Me.treeBranches.SelectedItem.key
If len(key) < 2 then
msgbox "invalid key: " & key
else
key = left(key, len(key) - 2)
end if
Me.description = key

HTH
Dale
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top