I have a treeview which is populated from a relational database. In order to
copy part of the tree, I need to add to the database the relationship of the
part of the tree to be copied but with new ids. I have built a collection of
the right number of ids. I am using the following code to recursively go
through the tree (some code left out). Pos is the position in the collection
of ids - I need to select the correct ids (need to use previous ids) to
maintain the node relationship which is done by testing node properties.
What is strange is that pos is the correct number in this routine but when
the last node is reached, pos changes to the wrong number. Any ideas or
another way to add a hierarchical relationship to a database from a set of
treeview nodes.
Private Sub Copy(ByVal n As TreeNode, ByVal pos As Integer)
Dim aNode As TreeNode
pos=pos+1
For Each aNode In n.Nodes
Copy(aNode, pos)
Next
End Sub
' Call the procedure using the top nodes of the treeview.
Private Sub CopyStart(ByVal aTreeView As TreeView)
Dim n As TreeNode
For Each n In aTreeView.Nodes
Copy(n,1)
Next
End Sub 6 1520
I'm not sure what your "Start" routine is doing here - do you want all of
your top level nodes to start off with the value "1"? If you want Unique
IDs then this is wrong, however, I'm guessing you want to label nodes by
their depth, in which case, its correct. When you say "pos is the position
in the collection of Ids" I get confused. What is the collection of Ids?
If pos is supposed to be a unique position, then Pos should be incremented
within the loops, not outside of them.
More information required I guess ;)
"Jan Krouwer" <ja*********@co mcast.net> wrote in message
news:nzOkb.8257 05$YN5.855111@s ccrnsc01... I have a treeview which is populated from a relational database. In order
to copy part of the tree, I need to add to the database the relationship of
the part of the tree to be copied but with new ids. I have built a collection
of the right number of ids. I am using the following code to recursively go through the tree (some code left out). Pos is the position in the
collection of ids - I need to select the correct ids (need to use previous ids) to maintain the node relationship which is done by testing node properties.
What is strange is that pos is the correct number in this routine but when the last node is reached, pos changes to the wrong number. Any ideas or another way to add a hierarchical relationship to a database from a set of treeview nodes.
Private Sub Copy(ByVal n As TreeNode, ByVal pos As Integer) Dim aNode As TreeNode
pos=pos+1
For Each aNode In n.Nodes Copy(aNode, pos) Next End Sub
' Call the procedure using the top nodes of the treeview. Private Sub CopyStart(ByVal aTreeView As TreeView) Dim n As TreeNode For Each n In aTreeView.Nodes Copy(n,1) Next End Sub
Thanks for your help
Rather than trying to figure this out, I abandoned recursion and changed the
routine to a Do While loop which works fine (has a test for firstnode to see
if child nodes are present). I have two of these loops. One is to build a
collection of unique ids (Guids) and the second loop is to get the data from
the database and change the ids (an event id and parent id) as required to
maintain the hierarchical relationship of the nodes and the fact that an
event id must be unique.
"Robin Tucker" <id************ *************@r eallyidont.com> wrote in
message news:bn******** ***********@new s.demon.co.uk.. . I'm not sure what your "Start" routine is doing here - do you want all of your top level nodes to start off with the value "1"? If you want Unique IDs then this is wrong, however, I'm guessing you want to label nodes by their depth, in which case, its correct. When you say "pos is the
position in the collection of Ids" I get confused. What is the collection of Ids? If pos is supposed to be a unique position, then Pos should be incremented within the loops, not outside of them.
More information required I guess ;)
"Jan Krouwer" <ja*********@co mcast.net> wrote in message news:nzOkb.8257 05$YN5.855111@s ccrnsc01... I have a treeview which is populated from a relational database. In
order to copy part of the tree, I need to add to the database the relationship of the part of the tree to be copied but with new ids. I have built a
collection of the right number of ids. I am using the following code to recursively go through the tree (some code left out). Pos is the position in the collection of ids - I need to select the correct ids (need to use previous ids) to maintain the node relationship which is done by testing node properties.
What is strange is that pos is the correct number in this routine but
when the last node is reached, pos changes to the wrong number. Any ideas or another way to add a hierarchical relationship to a database from a set
of treeview nodes.
Private Sub Copy(ByVal n As TreeNode, ByVal pos As Integer) Dim aNode As TreeNode
pos=pos+1
For Each aNode In n.Nodes Copy(aNode, pos) Next End Sub
' Call the procedure using the top nodes of the treeview. Private Sub CopyStart(ByVal aTreeView As TreeView) Dim n As TreeNode For Each n In aTreeView.Nodes Copy(n,1) Next End Sub
With Deft Fingers, "Jan Krouwer" <ja*********@co mcast.net> wrote: Rather than trying to figure this out, I abandoned recursion and changed the routine to a Do While loop which works fine (has a test for firstnode to see if child nodes are present). I have two of these loops. One is to build a
Boy I'd like to see that code (:
I've been bashing my head on Recursion without success. I've a 3d array with
parent/child info that I'm trying to create a treeview (the info quantities
vary... but never reach any excessive quanitity... say less than 30 total).
My parents and childs are 3 numbers (ie: 010-020 = parent-child). In my array
the parent and child are unique inputs.
Regards,
Bruce
Bruce,
Here is the code, with lengthy database code omitted.
Jan
Dim pos As Integer = 1
Dim ChildNode As TreeNode
'Routine starts at clicked node in treeview named TV
Dim SNode As TreeNode = TV.SelectedNode
'Check to make sure node was clicked
If IsNothing(SNode ) Then
MessageBox.Show ("You must select a node first")
Exit Sub
End If
'reset id collection
If Not IsNothing(AllNe wEventIDs) Then AllNewEventIDs = Nothing
AllNewEventIDs = New Collection
Cursor.Current = Cursors.WaitCur sor
'next code - not shown - deletes data from a table used to hold
copy information
'it is standard ado.net but would make this message long
'create unique id for starting node
Dim firsttime As Boolean = True
If firsttime = True Then
Dim EventGuid As Guid = Guid.NewGuid
AllNewEventIDs. Add(EventGuid.T oString)
End If
firsttime = False
'create unique id for all child nodes of parent
Do While Not IsNothing(SNode .FirstNode)
For Each ChildNode In SNode.Nodes
Dim EventGuid As Guid = Guid.NewGuid
AllNewEventIDs. Add(EventGuid.T oString)
Next ChildNode
'done with set of child nodes - set current node to last child
node to see if it has parents
SNode = ChildNode
'test if there are more children
If IsNothing(SNode .FirstNode) Then
Exit Do
End If
Loop
'reset starting conditions for second loop
SNode = TV.SelectedNode
firsttime = True
'most of next code - not shown - gets data from a table that has
node values stored in database
'then puts this data into a table that is later used in paste
operation
'it is standard ado.net but would make this message long
'code fragments left here shows how hierarachical relationship is
maintained
Dim numSib As Integer = 1
If firsttime = True Then
'get the data using SNode.tag in query which is event_id
'add same record to Temp table but give it new event_id
'parent_id for first record not important since it is always
changed in paste operation
dr("Event_Id") = AllNewEventIDs. Item(pos)
dr("Parent_ID" ) = "Dummy"
'increment position in collection
pos = pos + 1
End If
firsttime = False
Do While Not IsNothing(SNode .FirstNode)
For Each ChildNode In SNode.Nodes
'get the data for the rest of nodes using SNode.tag in query
which is event_id
'add same record to Temp table but give it new event_id
'parent_id depends on how many children
'get event_ID from collection
dr("Event_Id") = AllNewEventIDs. Item(pos)
dr("Parent_ID" ) = AllNewEventIDs. Item(pos - numSib)
pos = pos + 1
numSib = numSib + 1
Next ChildNode
'test if there are more children
SNode = ChildNode
numSib = 1
If IsNothing(SNode .FirstNode) Then
Exit Do
End If
Loop
Cursor.Current = Cursors.Default
Actually, the posted code has some problems - when tested for more cases -
sorry
"Jan Krouwer" <ja*********@co mcast.net> wrote in message
news:HH7lb.8424 24$uu5.149883@s ccrnsc04... Bruce,
Here is the code, with lengthy database code omitted.
Jan
Dim pos As Integer = 1
Dim ChildNode As TreeNode 'Routine starts at clicked node in treeview named TV
Dim SNode As TreeNode = TV.SelectedNode 'Check to make sure node was clicked
If IsNothing(SNode ) Then
MessageBox.Show ("You must select a node first")
Exit Sub
End If 'reset id collection
If Not IsNothing(AllNe wEventIDs) Then AllNewEventIDs = Nothing
AllNewEventIDs = New Collection Cursor.Current = Cursors.WaitCur sor 'next code - not shown - deletes data from a table used to hold copy information
'it is standard ado.net but would make this message long 'create unique id for starting node
Dim firsttime As Boolean = True
If firsttime = True Then
Dim EventGuid As Guid = Guid.NewGuid
AllNewEventIDs. Add(EventGuid.T oString)
End If
firsttime = False 'create unique id for all child nodes of parent
Do While Not IsNothing(SNode .FirstNode)
For Each ChildNode In SNode.Nodes
Dim EventGuid As Guid = Guid.NewGuid
AllNewEventIDs. Add(EventGuid.T oString)
Next ChildNode
'done with set of child nodes - set current node to last child node to see if it has parents
SNode = ChildNode
'test if there are more children
If IsNothing(SNode .FirstNode) Then
Exit Do
End If
Loop 'reset starting conditions for second loop
SNode = TV.SelectedNode
firsttime = True 'most of next code - not shown - gets data from a table that has node values stored in database
'then puts this data into a table that is later used in paste operation
'it is standard ado.net but would make this message long
'code fragments left here shows how hierarachical relationship is maintained Dim numSib As Integer = 1
If firsttime = True Then 'get the data using SNode.tag in query which is event_id
'add same record to Temp table but give it new event_id
'parent_id for first record not important since it is always changed in paste operation dr("Event_Id") = AllNewEventIDs. Item(pos)
dr("Parent_ID" ) = "Dummy" 'increment position in collection
pos = pos + 1 End If
firsttime = False Do While Not IsNothing(SNode .FirstNode)
For Each ChildNode In SNode.Nodes 'get the data for the rest of nodes using SNode.tag in query which is event_id
'add same record to Temp table but give it new event_id
'parent_id depends on how many children 'get event_ID from collection
dr("Event_Id") = AllNewEventIDs. Item(pos)
dr("Parent_ID" ) = AllNewEventIDs. Item(pos - numSib) pos = pos + 1
numSib = numSib + 1
Next ChildNode 'test if there are more children
SNode = ChildNode
numSib = 1
If IsNothing(SNode .FirstNode) Then
Exit Do
End If
Loop
Cursor.Current = Cursors.Default
With Deft Fingers, "Jan Krouwer" <ja*********@co mcast.net> wrote: Actually, the posted code has some problems - when tested for more cases - sorry
Oh... Ok... but thanks anyways. I might find something useful to my case
anyways (always nice seeing others code regardless).
Regards,
Bruce This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: alanrn |
last post by:
I am using a TreeView to display the hierarchy of a strongly-typed collection
(inherited from CollectionBase). The order of the nodes in the TreeView is
strictly tied to the order in which they appear in the underlying collection.
However, the user must be able to reorder certain items in the
collection--and, hence, the TreeView.
I have created a context-sensitive menu that allows the user to move an item
in the collection either up or...
|
by: feel |
last post by:
Goin' crazy with this recursive function ported from delphi...
I send a string like DirA/ DirB /DirC but i get in the treeView
each one in a new node.Cant get the child node....!!
-DirA
-DirB
-DirC
instead of:
DirA
|
- DirB
|
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?
|
by: Chris |
last post by:
Hi,
anyone experience with the TreeView control that is available in the
Microsoft.Web.UI.WebControls component ?
I want to add a few nodes to the TreeView-control but don't know quite how :
// Creating a few nodes
TreeNode node1 = new TreeNode();
node1.Text = "Canada";
|
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
| |
by: garyusenet |
last post by:
Hi All,
I'm eagerly anticipating what you have to say on something that's
stumped me over the weekend. I'm writing a small application which
utilises a treeview control. I've figured out how to programatically
add nodes to it, but everytime the program is exited the treeview
control resets itself.
I looked for a save method or something similair but there doesn't seem
to be one. I have found the copyto method, and figured out how to...
|
by: |
last post by:
What's the best way to create new nodes on a treeview 2.0 and save them to
an xml file?
Thanks,
Victor
|
by: John Dann |
last post by:
I'm trying to implement a fairly simple Treeview procedure but running
into problems.
My Treeview has just two levels of nodes: top-level and one child
level. I want a doube-click on the Treeview to do one of two things:
If the double-click was on a top-level node then the default action of
exapnding/collapsing the node should be allowed as usual and with no
further action.
|
by: balurajeev84 |
last post by:
Hi,
I am trying to convert a VB.net code to C# .
it is to bind a treeview from a collection. but not finding a Collection which stores treenodes as object.
Cant use hashtable since it automatically sorts the data by key.
Can anybody tell me a collection which takes objects and doesn't sort it.
|
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,...
|
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...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
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();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |