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

TreeView problem (should be simple...)

Hi guys

I'm needing to create a fairly complex TreeView, but am faltering on a very
basic step (as you will gather, I'm new-ish to .net).

Simplified, I can't get the creation of two nodes (with children) to work.

I've got a TreeView called tvwSword and have put the following code into the
Form1_Load:
Dim nodeParent As TreeNode
Dim nodeChild As TreeNode

nodeParent = New TreeNode("2001")
tvwSword.Nodes.Add(nodeParent) ' adds parent of 2001
nodeParent.Nodes.Add("2001/1") ' adds child of 2001/1 to parent of 2001

nodeParent = New TreeNode("2002")
tvwSword.Nodes.Add(nodeParent) ' adds parent of 2002
nodeParent.Nodes.Add("2002/1") ' adds child of 2002/1 to parent of 2002

' the above lines work fine

nodeParent = New TreeNode("2001")
nodeChild = New TreeNode("2001/2")
nodeParent.Nodes.Insert(1, nodeChild) ' adds child of 2001/2 to parent of
2001

' these 3 lines do nothing ?????

tvwSword.Show()

Now, I would have expected this to read:

2001
--- 2001/1
--- 2001/2
2002
--- 2002/1

but it doesn't insert the second child (2001/2).

If I change it to

nodeParent = New TreeNode("2001")
nodeChild = New TreeNode("2001/2")
nodeParent.Nodes.Add(nodeChild)

I get the same effect.

Under VB6.0 I would have used keys and the problem of children is resolved,
but I can't see how to do it in VB.Net. I think it may be something to do
with SelectedNode, but I can't see what.

What am I missing????

TIA

Rabbit

Nov 20 '05 #1
7 1725
Cor
Hi Metal Rabbit
nodeParent = New TreeNode("2001")
Here you declare a new treeNode that you never add to the tree

To get your expected result, you can do.
nodeParent=tvwSword.Nodes(0)
nodeChild = New TreeNode("2001/2")
nodeParent.Nodes.Insert(1, nodeChild) ' adds child of 2001/2 to parent of


I hope this helps?

Cor
Nov 20 '05 #2
* "Metal Rabbit" <MR***@swordsystems.demon.co.uk> scripsit:
' the above lines work fine

nodeParent = New TreeNode("2001")
nodeChild = New TreeNode("2001/2")
nodeParent.Nodes.Insert(1, nodeChild) ' adds child of 2001/2 to parent of


I don't understand what's the problem... Why not use something like
this?

\\\
Dim t As TreeNode = New TreeNode("Parent")
t.Nodes.Add("Child1")
t.Nodes.Add("Child2")
Me.TreeView1.Nodes.Add(t)
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3
Cor
Hi Herfried,

I can say see my post, but I also see again disapearing messages in the
Microsoft newsgroups, is that with you also?

Cor
Nov 20 '05 #4
* "Cor" <no*@non.com> scripsit:
I can say see my post, but I also see again disapearing messages in the
Microsoft newsgroups, is that with you also?


No, for some reason everything works... I don't have any problems
accessing the groups today (but some others have).

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #5
Hi Cor:

That gets me closer, but what I'm trying to do is to add children to
existing nodes according to certain values. For instance, if I already have
high-level nodes of

2001
2002
2004
2005
2007
2009

and I read a field value (from a database) of "2004" (with another field of
"2004/12" elsewhere in the record), then I want to add a child of "2004/12"
to the high-level node of 2004, giving:

2001
2002
2004
----2004/12
2005
2007
2009

Do I need to store the indexes of each of the top level nodes, find the
appropriate index and then use

nodeParent=tvwSword.Nodes(index)

or is there a way to easily find the index 'on the fly'?

Thanks

Rabbit
"Cor" <no*@non.com> wrote in message
news:#P**************@TK2MSFTNGP11.phx.gbl...
Hi Metal Rabbit
nodeParent = New TreeNode("2001")
Here you declare a new treeNode that you never add to the tree

To get your expected result, you can do.
nodeParent=tvwSword.Nodes(0)
nodeChild = New TreeNode("2001/2")
nodeParent.Nodes.Insert(1, nodeChild) ' adds child of 2001/2 to parent

of
I hope this helps?

Cor

Nov 20 '05 #6
"Cor" <no*@non.com> schrieb

I can say see my post, but I also see again disapearing messages in the
Microsoft newsgroups, is that with you also?


Probably due to reindexing of the messages in this group. Had some minor
problems yesterday night, too.
--
Armin

Nov 20 '05 #7
Cor
Hi Metal Rabbit,

I could wait for it.

I have also answered your next qeustion
"2001" is a certain value.
I hope this helps?

Cor

\\\
For Each nd As TreeNode In tvwSword1.Nodes
If nd.Text = "2001" Then
ind = nd.Index
Exit For
End If
Next
nodeParent = tvwSword1.Nodes(ind)
ind = nodeParent.LastNode.Index()
nodeChild = New TreeNode("2001/" & (ind + 2).ToString)
nodeParent.Nodes.Insert(ind + 1, nodeChild) ' adds child of 2001/2 to parent
of 2001:
///
Nov 20 '05 #8

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

Similar topics

4
by: John Winterbottom | last post by:
I've a requirement for a treeview control to display a master-detail view. So instead of the old the old 'ActiveX + 1,000 lines of code' method that I've used in the past. I decided to try a...
42
by: lauren quantrell | last post by:
So many postings on not to use the treeview control, but nothing recently. Is it safe to swim there yet with Access 2000-Access 2003?
3
by: Soul | last post by:
Hi, I am learning C# at the moment. I am trying to develop a simple program that will get data from a MS Access database into a dataSet. The result of dataSet should be something like: Year ...
4
by: Ian Powell | last post by:
Hi I've got objects in an sorted ArrayList like: P:\ P:\\DOCS P:\\i386 P:\\i386\ASMS P:\\i386\ASMS\1000 P:\\i386\ASMS\1000\MSFT
7
by: Mike | last post by:
hi everyone! i'm searching for a tutorial or an example for how to fill a treeview with information from my ms sql database. i've found some on "code project" and other sites, but nothing like a...
0
by: MarkD | last post by:
I have an ASP.NET (VB.NET) application that calls all VB6 COM DLL via Interop. The DLL uses functionality contained in a Custom OCX Control (Also VB6) that in turn contains a standard TreeView...
17
by: Spam Trap | last post by:
I am upgrading from VB6 where I had access to a treeview NodeClick event (see below)... but now VB.NET does not have this any more. Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)...
12
by: Bob Hollness | last post by:
Hi. I have a text file containing a list of files and their path. I.e. c:\MyDocs\File1.txt c:\MyDocs\File2.txt c:\MyDocs\File3.txt c:\MyDocs\File4.txt C:\MyDocs\Folder\File1.txt
0
by: Treeview Trouble | last post by:
I have an application where there are two radio buttons each of which populates a treeview control with a directory structure. Each radio button corresponds to a different directory which may or...
3
by: =?Utf-8?B?TGVzbGll?= | last post by:
Using Visual Studio 2005 SP1 I am attempting to dynamically load a treeview control. I create an XmlDataSource and then load the data source using XmlDataSource.Data. I Load my XML string into...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.