|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
SelectednodeHello,
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 "Jerry" <jerry***@gmx.net> schrieb: You'll have to assign a tree node object to the property instead of a > 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? string. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://dotnet.mvps.org/dotnet/faqs/> I'm not too firm with VB yet. Could you give me an example?
Thanks, Jerry Show quoteHide quote "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> schrieb im Newsbeitrag news:eM0DxykvGHA.560@TK2MSFTNGP05.phx.gbl... > "Jerry" <jerry***@gmx.net> schrieb: >> 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/> "Jerry" <jerry***@gmx.net> ha scritto nel messaggio The SelectedNode property is not a string, so you cannot assign a string to news:eblemu$ag3$00$1@news.t-online.com... > I'm not too firm with VB yet. Could you give me an example? > 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. 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 Show quoteHide quote "Fabio" <znt.fa***@virgilio.it> schrieb im Newsbeitrag news:uVRScqlvGHA.4296@TK2MSFTNGP06.phx.gbl... > "Jerry" <jerry***@gmx.net> ha scritto nel messaggio > news:eblemu$ag3$00$1@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 > 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 Now that's something I can work with, thanks!
Me.tvwMenu.SelectedNode = Me.tvwMenu.Nodes(0).Nodes(0) did the trick. Thank you, Jerry Show quoteHide quote "Oenone" <oen***@nowhere.com> schrieb im Newsbeitrag news:NuBDg.13536$Cz6.11837@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 > 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: Show quoteHide quote > 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 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.TreeView1) '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: Show quoteHide quote > 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 |
|||||||||||||||||||||||