473,320 Members | 1,814 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,320 software developers and data experts.

Selectednode

Hello,

I am able to GET the selected node with my code. I would however like to SET
any node with code. Something like
me.treeview.selectednode="First"
But this doesn't work. I can't find anything on setting this property. Can
you help?
Thanks,

Jerry


Aug 12 '06 #1
8 4160
"Jerry" <je******@gmx.netschrieb:
I am able to GET the selected node with my code. I would however like to
SET any node with code. Something like
me.treeview.selectednode="First"
But this doesn't work. I can't find anything on setting this property. Can
you help?
You'll have to assign a tree node object to the property instead of a
string.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Aug 12 '06 #2
I'm not too firm with VB yet. Could you give me an example?

Thanks,

Jerry


"Herfried K. Wagner [MVP]" <hi***************@gmx.atschrieb im Newsbeitrag
news:eM*************@TK2MSFTNGP05.phx.gbl...
"Jerry" <je******@gmx.netschrieb:
>I am able to GET the selected node with my code. I would however like to
SET any node with code. Something like
me.treeview.selectednode="First"
But this doesn't work. I can't find anything on setting this property.
Can you help?

You'll have to assign a tree node object to the property instead of a
string.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Aug 12 '06 #3
"Jerry" <je******@gmx.netha scritto nel messaggio
news:eb*************@news.t-online.com...
I'm not too firm with VB yet. Could you give me an example?
The SelectedNode property is not a string, so you cannot assign a string to
it.

If you need to search a node using its key you can use Nodes.Find() or
Nodes.IndexOf() to get the node and then you can select it via SelectedNode
property.
--

Free .Net Reporting Tool - http://www.neodatatype.net
Aug 12 '06 #4
Jerry wrote:
I'm not too firm with VB yet. Could you give me an example?
To select the first node as the selected node:

\\\
Me.TreeView.SelectedNode = Me.TreeView.Nodes(0)
///

To select a different node you will need to locate the appropriate Node
within the Nodes collection, and then pass that to the SelectedNode
property.

--

(O)enone
Aug 13 '06 #5
Hi jerry,

Sub TreeView_EnsureFirstNodeIsSelectedIfExist(ByVal Treeview As
TreeView)
If Treeview.Nodes.Count = 0 Then Exit Sub
Treeview.SelectedNode = Treeview.Nodes(0)
End Sub
usually one wishes that the AfterSelect event be fired even though the
node is selected already (for 2003 replace isNot with if not...is):
Sub TreeView_ForceSelectFirstNodeIfExist(ByVal Treeview As
TreeView)
If Treeview.Nodes.Count = 0 Then Exit Sub
If Treeview.SelectedNode IsNot Nothing Then
Treeview.SelectedNode = Nothing
Treeview.SelectedNode = Treeview.Nodes(0)
End Sub

example

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Me.TreeView1.HideSelection = False
Me.TreeView1.Nodes.Clear()
Me.TreeView1.Nodes.Add(New TreeNode("Hi Jerry"))

TreeView_ForceSelectFirstNodeIfExist(Me.TreeView1)

End Sub

Private Sub TreeView1_AfterSelect(ByVal sender As System.Object,
ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles
TreeView1.AfterSelect
MsgBox("Selected " & e.Node.Text)
End Sub

End Class

-tommaso


Jerry ha scritto:
Hello,

I am able to GET the selected node with my code. I would however like to SET
any node with code. Something like
me.treeview.selectednode="First"
But this doesn't work. I can't find anything on setting this property. Can
you help?
Thanks,

Jerry
Aug 13 '06 #6
Hi,
I have a revision already :)

(i have added an if to the first sub)
Please suggest improvements if any...

-tommaso
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Me.TreeView1.HideSelection = False
Me.TreeView1.Nodes.Clear()
Me.TreeView1.Nodes.Add(New TreeNode("Hello"))

TreeView_EnsureFirstNodeIsSelectedIfExist(Me.TreeV iew1)

'Force selection again
TreeView_ForceSelectFirstNodeIfExist(Me.TreeView1)

End Sub

Private Sub TreeView1_AfterSelect(ByVal sender As System.Object,
ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles
TreeView1.AfterSelect
MsgBox("Selected " & e.Node.Text)
End Sub
Sub TreeView_EnsureFirstNodeIsSelectedIfExist(ByVal Treeview As
TreeView)
If Treeview.Nodes.Count = 0 Then Exit Sub
If Treeview.SelectedNode IsNot Treeview.Nodes(0) Then
Treeview.SelectedNode = Treeview.Nodes(0)
End Sub

Sub TreeView_ForceSelectFirstNodeIfExist(ByVal Treeview As
TreeView)
If Treeview.Nodes.Count = 0 Then Exit Sub
If Treeview.SelectedNode IsNot Nothing Then
Treeview.SelectedNode = Nothing
Treeview.SelectedNode = Treeview.Nodes(0)
End Sub

End Class



tommaso.gasta...@uniroma1.it ha scritto:
Hi jerry,

Sub TreeView_EnsureFirstNodeIsSelectedIfExist(ByVal Treeview As
TreeView)
If Treeview.Nodes.Count = 0 Then Exit Sub
Treeview.SelectedNode = Treeview.Nodes(0)
End Sub
usually one wishes that the AfterSelect event be fired even though the
node is selected already (for 2003 replace isNot with if not...is):
Sub TreeView_ForceSelectFirstNodeIfExist(ByVal Treeview As
TreeView)
If Treeview.Nodes.Count = 0 Then Exit Sub
If Treeview.SelectedNode IsNot Nothing Then
Treeview.SelectedNode = Nothing
Treeview.SelectedNode = Treeview.Nodes(0)
End Sub

example

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Me.TreeView1.HideSelection = False
Me.TreeView1.Nodes.Clear()
Me.TreeView1.Nodes.Add(New TreeNode("Hi Jerry"))

TreeView_ForceSelectFirstNodeIfExist(Me.TreeView1)

End Sub

Private Sub TreeView1_AfterSelect(ByVal sender As System.Object,
ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles
TreeView1.AfterSelect
MsgBox("Selected " & e.Node.Text)
End Sub

End Class

-tommaso


Jerry ha scritto:
Hello,

I am able to GET the selected node with my code. I would however like to SET
any node with code. Something like
me.treeview.selectednode="First"
But this doesn't work. I can't find anything on setting this property. Can
you help?
Thanks,

Jerry
Aug 13 '06 #7
I hear what your saying, but I'm afraid I can't do it.

I have one parent node, node1 and three child nodes, child1, child2, child3.
They are fixed and don't change. They all have a tag, parent, one, two and
three. Making things happen when I select them is no problem. But when the
form loads, I want child1 to be selected, not parent. So lets say I want
code to select child3 by tag or lable what is the code for doing so?

Forgive me, but I am learning by copying code and changing it to my needs.
"objects" "classes" and so on are only words to me. I know I have to learn,
but for now I'd like to keep it simple.
Thanks,

Jerry

"Fabio" <zn*******@virgilio.itschrieb im Newsbeitrag
news:uV**************@TK2MSFTNGP06.phx.gbl...
"Jerry" <je******@gmx.netha scritto nel messaggio
news:eb*************@news.t-online.com...
>I'm not too firm with VB yet. Could you give me an example?

The SelectedNode property is not a string, so you cannot assign a string
to it.

If you need to search a node using its key you can use Nodes.Find() or
Nodes.IndexOf() to get the node and then you can select it via
SelectedNode property.
--

Free .Net Reporting Tool - http://www.neodatatype.net

Aug 13 '06 #8
Now that's something I can work with, thanks!

Me.tvwMenu.SelectedNode = Me.tvwMenu.Nodes(0).Nodes(0) did the trick.

Thank you,

Jerry

"Oenone" <oe****@nowhere.comschrieb im Newsbeitrag
news:Nu*******************@newsfe5-win.ntli.net...
Jerry wrote:
>I'm not too firm with VB yet. Could you give me an example?

To select the first node as the selected node:

\\\
Me.TreeView.SelectedNode = Me.TreeView.Nodes(0)
///

To select a different node you will need to locate the appropriate Node
within the Nodes collection, and then pass that to the SelectedNode
property.

--

(O)enone

Aug 13 '06 #9

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

Similar topics

4
by: David Elliott | last post by:
Hi, I have a Windows Explorer-like treeview that displays directories. After a cut/paste operation, I want the treeview to display the folder where the paste happened. But, I'm running into a...
1
by: yfzhu | last post by:
I want a filter: "menu_id = " + treeview1.selectedNode.tag? why it can not run?
3
by: Polo | last post by:
Hi, How can I set the SelectedNode (by code) visible in the tree (the first visible node in the control) ? thank's
1
by: jyoti ranjan | last post by:
i have a ie webcontrols treeview in my application. by default treeview is selecting the first node as selected index. i don't want a default selectednode. how can i get that one . can any body pls...
4
by: Able | last post by:
Dear friends I remove the selected node in a treeview like this: TreeView1.SelectedNode.Remove When this is done I see something odd has happened. That is the tag and text properties of the...
1
by: Progalex | last post by:
Hi, I have a treeview, called Treeview1 with one father node and some children nodes. Number of children nodes can change since every child node is a file name that the user add through an Open...
0
by: Bobby Owens | last post by:
Hi, I'm current having a problem with the treeview control and multi threading. The treeview is on a form. A request is then sent to a server using IP for the data. The data arrives in an event...
1
by: Dean Hinson | last post by:
Hello, I am trying to spawn a sunroutine in a worker thread for populating a trreeview. I set the selectednode and then start the thread. However, the thread errors because the selectednode was...
0
by: stacy | last post by:
My asp.net Web application is written in VB, using VS 2005 with Framework 2.0 I am having trouble with the SelectedNode element. The TreeView is built programmatically and looks like this: -...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.