Re: This code demonstrates a problem using a treeview twice
- From: " Franky" <frankieNOSPAM@xxxxxxxxxx>
- Date: Sat, 9 Dec 2006 11:24:21 -0500
I know if I reinitialize the treeview it woks OK.
But I wanted to retain the reference so that it would retain the users
last expansions.
When I show it the second time I want it to look like it did when it
finished the last time.
Not possible?
If it stays in memory why does it behave differently if I leave and
comeback?
If I do the search twice with the first ShowDialog, it works OK both
times.
Do this in Load and notice that there are two folders expanded.
ExpandPath("C:\Documents and Settings\All Users\Start Menu")
ExpandPath("C:\Documents and Settings\All Users\Documents\My Music")
However, the equivalent can't be done by putting and clicking a second
button on Form2 to expand My Music without collapsing StartMenu
Thanks for the reply
"Tom Shelton" <tom_shelton@xxxxxxxxxxxxxxxxxx> wrote in message
news:2JOdnYpQTdwzr-fYnZ2dnUVZ_qunnZ2d@xxxxxxxxxxxxxx
On 2006-12-08, Franky <frankieNOSPAM@xxxxxxxxxx> wrote:
Been having a problem using a treeview. Work great the first time the
form
containing it is entered but not the second time.
Took a while to create a small sample that exhibits the problem, but
here it
is.
Seems to have something to do with doing ShowDialog
Franky - the problem has nothing to do with ShowDialog. The problem is
that
you are keeping a reference to the form and showing it over and over
again -
so it never gets it's state reset.
You can fix it one of two ways...
1. change the form load of the treeview form like this:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
'Static beenHereBefore As Boolean 'Need to initialize the tree
'If Not beenHereBefore Then 'Add C: to the tree the first time
TreeView1.Nodes.Clear()
Dim SubNode As TreeNode = TreeView1.Nodes.Add("C:")
SubNode.Tag = "C:"
Dim tn As TreeNode = SubNode.Nodes.Add("DUMMY")
tn.Tag = "DUMMY"
'End If
ExpandPath("C:\Program Files")
End Sub
Notice, I'm just letting the tree re-init each time.
2. Change the calling form to not keep a reference at all - and then
just
create a new form each time the button is clicked:
Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Using f As New Form1
f.ShowDialog(Me)
End Using
End Sub
HTH
--
Tom Shelton
.
- References:
- This code demonstrates a problem using a treeview twice
- From: Franky
- Re: This code demonstrates a problem using a treeview twice
- From: Tom Shelton
- Re: This code demonstrates a problem using a treeview twice
- From: Franky
- This code demonstrates a problem using a treeview twice
- Prev by Date: Re: destroying/releasing objects from memory?
- Next by Date: Re: destroying/releasing objects from memory?
- Previous by thread: Re: This code demonstrates a problem using a treeview twice
- Next by thread: Graphics challenge
- Index(es):
Relevant Pages
|