Treeview before expand event

Hi
I am stuck with a problem,please help me.
I have a requirement in which i have some nodes in a treeview and When the treeview is populated the first time I do not populate the child nodes.I only add dummy nodes in the begining. Only when the user clicks on the "+" sign i delete the dummy node and add the actual child nodes. While doing this,as soon as the user clicks on the parent node a messagebox is fired asking the user whether to continue. The coding for the messagebox is writen in the expand event of the treeview .The problem is when the user clicks on the "+" sign the messagebox is fired but at the same time the dummy node which was added as the child node is also visible(which is not favourable). So please suggest a solution where I can fire the message box before the child node(Dummy Node) is visible. Is there anything through which i can access the before expand event of a treeview node.
Thanks in Advance
Regards
Sravanthi
[969 byte] By [sravanthi] at [2007-11-15 16:17:31]
# 1 Re: Treeview before expand event
Try deleting the dummy node followed by a Treeview.Refresh then issue your messageBox.

John G
John G Duffy at 2007-11-10 0:59:02 >
# 2 Re: Treeview before expand event
Hi
Thanks for the suggestion but my problem is that i do not want to delete the dummy node untill the user presses the yes button on the message box.
I am copying a code snipet which will give a clear idea of the situation
place a treeview on the form and paste the following code.

Private Sub Form_Load()
Dim i As Integer
Dim nodex As Node
TreeView1.Style = tvwTreelinesPlusMinusText
TreeView1.LineStyle = tvwRootLines
For i = 1 To 10
Set nodex = TreeView1.Nodes.Add(, , , "Parent node" & i)
TreeView1.Nodes.Add nodex, tvwChild, , "Dummy"
Next
End Sub

Private Sub TreeView1_Expand(ByVal Node As MSComctlLib.Node)
Dim a As Integer
a = MsgBox("Do you want the node to expand?", vbYesNo, "Confirmation")
If a = vbYes Then
TreeView1.Nodes.Remove (Node.Child.Index)
For i = 1 To 5
TreeView1.Nodes.Add Node, tvwChild, , "Childnode" & 5
Next
Else
Node.Expanded = False
End If
End Sub

regards
Sravanthi
sravanthi at 2007-11-10 1:00:04 >
# 3 Re: Treeview before expand event
Hi John
Thanks for the suggestion but my problem is that i do not want to delete the dummy node untill the user presses the yes button on the message box.
I am copying a code snipet which will give a clear idea of the situation
place a treeview on the form and paste the following code.

Private Sub Form_Load()
Dim i As Integer
Dim nodex As Node
TreeView1.Style = tvwTreelinesPlusMinusText
TreeView1.LineStyle = tvwRootLines
For i = 1 To 10
Set nodex = TreeView1.Nodes.Add(, , , "Parent node" & i)
TreeView1.Nodes.Add nodex, tvwChild, , "Dummy"
Next
End Sub

Private Sub TreeView1_Expand(ByVal Node As MSComctlLib.Node)
Dim a As Integer
a = MsgBox("Do you want the node to expand?", vbYesNo, "Confirmation")
If a = vbYes Then
TreeView1.Nodes.Remove (Node.Child.Index)
For i = 1 To 5
TreeView1.Nodes.Add Node, tvwChild, , "Childnode" & 5
Next
Else
Node.Expanded = False
End If
End Sub

regards
Sravanthi
sravanthi at 2007-11-10 1:00:58 >
# 4 Re: Treeview before expand event
Understand what your problem is. Delete the dummy on entry then add it back after the msgBox OR use this not so elegant solution. WHat you really are looking for is a way to tell the control to ignore the users Expand request until your program decides its OK to expand. Unfortunately I know of no way to do this. Try this out though

private Sub TreeView1_Expand(byval Node as MSComctlLib.Node)
Dim a as Integer
Node.Expanded = false ' ASSUME no expansion
a = MsgBox("Do you want the node to expand?", vbYesNo, "Confirmation")
If a = vbYes then
TreeView1.Nodes.Remove (Node.Child.Index)
Node.Expanded = true ' open it up
for i = 1 to 5
TreeView1.Nodes.Add Node, tvwChild, , "Childnode" & 5
next
End If
End Sub

John G
John G Duffy at 2007-11-10 1:02:06 >
# 5 Re: Treeview before expand event
Hi Mr.John
Thank You Very much.
Regards
Sravanthi
sravanthi at 2007-11-10 1:03:10 >
# 6 Re: Treeview before expand event
Hi
The first solution was ok.But in the case of the second solution the expand event recursively occurs because inside the expand event we are expanding the node again.I am excactly looking for some event where we can validate the expansion of a node.
Regards
Sravanthi.
sravanthi at 2007-11-10 1:04:01 >
# 7 Re: Treeview before expand event
In my tests I do not get a re-entry on node expansion but this situation is not uncommon. To prevent reexecuting the code simply insert a Boolean switch and exit if it is set. Here is my revised example

private Sub TreeView1_Expand(byval Node as MSComctlLib.Node)
static blNoEntry as Boolean
Dim a as Integer
If blNoEntry then Exit Sub
Node.Expanded = false ' ASSUME no expansion
a = MsgBox("Do you want the node to expand?", vbYesNo, "Confirmation")
If a = vbYes then
TreeView1.Nodes.Remove (Node.Child.Index)
blNoEntry = true
Node.Expanded = true ' open it up
blNoEntry = false
for i = 1 to 5
TreeView1.Nodes.Add Node, tvwChild, , "Childnode" & 5
next
End If
End Sub

John G
John G Duffy at 2007-11-10 1:05:05 >
# 8 Re: Treeview before expand event
Hi Mr.John
Thank you very much for your responses.They have worked on VB.
But still my problem is persistant. My actual problem is as follows.--I am making a treeview control to be used in a erp which is coded in a language called panther. There already exists a treeview control which is being used in that erp(coded in some other language).Now I am making this control with some additional functionality to be replaced in the erp(whereever the older version of the treeview was used).In the older version there is an event called treeview expand which raises as soon as the "+" sign is clicked and before the childnodes are displayed.The problem is, how i give them such an event.
Your earlier solutions would work if i had the rights to change the coding in the erp which unortunately is not there.
So give me some solution if there is one.
Thank you very much
Regards
Sravanthi.
sravanthi at 2007-11-10 1:06:12 >