473,938 Members | 17,774 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Programitically Adding items to TreeView

VS,VB 2005

I have a treeview which i load data into in the forms load event
Adding Nodes and Children to the parent nodes works fine

to add a parent:
Me.tvGroups.Nod es.Add(GroupDat aRow(0)("MenuGr oupID").ToStrin g,
GroupDataRow(0) ("GroupLabel "))

to add a child to a Parent:
ParentIndex =
Me.tvGroups.Nod es.IndexOfKey(G roupDataRow(0)( "ParentGroupID" ).ToString)
NodeRef = Me.tvGroups.Nod es(ParentIndex)
NodeRef.Nodes.A dd(GroupDataRow (0)("MenuGroupI D").ToString ,
GroupDataRow(0) ("GroupLabel "))

all works good... but now im trying to add a child to a child and i am
unable to get the parent index by key the same way as above. this code fails
when its a child key im looking for:

ParentIndex =
Me.tvGroups.Nod es.IndexOfKey(G roupDataRow(0)( "ParentGroupID" ).ToString)

suggestions???
May 7 '07 #1
6 2801

also, if i insert a new node, child, grandchild, etc... how do i make the
inserted node the selected node?
May 7 '07 #2
To select the node, set its Selected property (from .Net 2.0 onwards) to
true.

---------
- G Himangi, Sky Software http://www.ssware.com
Shell MegaPack : GUI Controls For Drop-In Windows Explorer like Shell
Browsing Functionality For Your App (.Net & ActiveX Editions).
EZNamespaceExte nsions.Net : Develop namespace extensions rapidly in .Net
EZShellExtensio ns.Net : Develop all shell extensions,expl orer bars and BHOs
rapidly in .Net
---------

"Brad" <Br**@discussio ns.microsoft.co mwrote in message
news:7A******** *************** ***********@mic rosoft.com...
>
also, if i insert a new node, child, grandchild, etc... how do i make the
inserted node the selected node?

May 8 '07 #3
useing .net 2

first, i can find no Selected Property, what is it under?

second, back to my first problem...

if i am looking for the index to a node that is a granchild, using
IndexOfKey returns a -1, it cant find the granchild. How do i find the Index?

if i have an Index, how do i set the node to selected?


"G Himangi" wrote:
To select the node, set its Selected property (from .Net 2.0 onwards) to
true.
May 8 '07 #4
solving my first problem gives me the solution for the rest of them

this code is not my origional creation....

i created 2 functions that when passed a Key Value (Nodes.Name) it will
return the Node i referenced and the rest is simple

this allows me to find a node that is a parent, child, grandchild, great
grandchild, etc... by passing the key (or Name) associated with it...

Public Function FindNodeByNodeN ame(ByVal NodeName As String) As TreeNode
Return SelectNode(Me.t vGroups.Nodes, NodeName)
End Function

Private Function SelectNode(ByVa l Nodes As TreeNodeCollect ion, ByVal
NodeName As String) As TreeNode
Dim foundNode As TreeNode = Nothing
Dim i As Integer = 0

Do Until Not foundNode Is Nothing OrElse i = Nodes.Count
If DirectCast(Node s(i), TreeNode).Name = NodeName Then
foundNode = DirectCast(Node s(i), TreeNode)
Else
If Nodes(i).Nodes. Count 0 Then
foundNode = SelectNode(Node s(i).Nodes, NodeName)
End If

i += 1
End If
Loop
Return foundNode
End Function

May 8 '07 #5
..Selected???

this works...

Me.tvName.Selec tedNode = Me.tvName.Nodes (NodeIndexToSel ect)

May 8 '07 #6
while were at it, to locate a child, grandchild, etc.. to add another node
to...

could be spead up by useing tvname.nodes.fi nd(KeyText,True ) to see if you
should even bother going down the tree any further

May 8 '07 #7

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

Similar topics

4
14199
by: Aaron Queenan | last post by:
How can I use the designer to add a context menu to a class which inherits from a control, e.g. treeview, without adding the context menu to a form? For example, to add a context menu with "Select All" and "Clear Selection" to a checked list box? Thanks, Aaron Queenan.
4
13166
by: Chuck Bowling | last post by:
I have a serialized TreeNodeCollection that I want to initialize a TreeView with. Is there a simple assignment I can use for this or do I have to iterate thru the collection and add individual Nodes?
10
21353
by: tmaster | last post by:
When I try to dynamically add a second sub menu item to this ContextMenu item, I get an error 'Specified argument was out of the range of valid values'. Private Sub mnuTopics_Show_Select(ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles mnuTopics_Show.Select Dim mShowMenuItem As MenuItem mShowMenuItem = DirectCast(sender, MenuItem)
4
2323
by: pmcguire | last post by:
I have a treeview with a lot of nodes. I want to load only the nodes that are initially visible when the form loads, and then continue to populate it in background and/or when the nodes are required by the user either scrolling or performing some other action that would move the treeview window to a particular "unloaded" node in the treeview Any advice on how to go about this? It seems I need a way of sensing a scroll event in the treeview...
7
10424
by: Progalex | last post by:
Hi everybody! I have a listview and a treeview in a form . With an OpenDialog I let the user select multiple files and then these files are added to the listview with the complete pathname, while they are added to the treeview without the path (only file name). I'd like the user would be able to remove multiple items selecting filenames from the listview. So, items should be removed both from the listview and the treeview. How can I do...
3
2275
by: Ray Booysen | last post by:
Hi all I have a treeview bound to a sitemap. Once the user is logged in, I'm wanting the menu to expand to include additional items from a database while retaining the items in the sitemap. Is this possible. For example. My menu has an item called "Books" defined in the sitemap. Once the user logs in, I want sub menu-items to be created under books with all
0
16333
debasisdas
by: debasisdas | last post by:
This sample code displays employee name in the treeview control from the emp table of Scott schema in oracle database. To start with Select Microsoft windows common controls 6.0 (SP6) from components Add a TreeView and a ListView control to the form. Add this sample code to the form ========================== Dim con As New ADODB.Connection
2
1363
by: michelqa | last post by:
Hi, I'm trying to add nodes to a specific node of a treeview. With VS 2005 and more (>= .net 2.0) I can set the Nodes.Name property and then use Nodes.Find("MyNodeName",true) to add nodes to a particular node of my treeview. ex :
0
1271
by: metricspaces | last post by:
Hi, I'm using VB6 and the TreeView from "Microsoft Windows Common Controls.". Due to the bug http://support.microsoft.com/kb/182231 it is not possible to add more than 32767 nodes to the tree. I want to add 100,000's items to the TreeView. Is there anywork around for this problem? Is there any other implementation of TreeView that I can use with VB6 and does not suffer from this problem?
0
9963
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11521
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
11285
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
8216
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7379
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6292
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4901
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4444
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3498
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.