Re: This code demonstrates a problem using a treeview twice

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




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





.



Relevant Pages

  • Re: This code demonstrates a problem using a treeview twice
    ... 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 ... 'Static beenHereBefore As Boolean 'Need to initialize the tree ... Private Sub Button1_Click(ByVal sender As Object, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Using Drag and Drop between controls
    ... ' Project must have a component reference to: ... ' Fires then mouse button is pressed to the down position, ... Private Sub TreeView1_MouseDown(_ ... Dim oTargetNode As Node ...
    (microsoft.public.vb.controls)
  • Compatibilty between .NET framework and EXCEL
    ... COM object I wrote in C# from EXCEL (see VB code ... one using a reference ... Private Sub moComObj_MyEvent(ByVal StringParam As String) ...
    (microsoft.public.excel.programming)
  • Re: Problem with reference counting
    ... creates it, it stores an uncounted reference to the object, using its key. ... Private Sub Class_Initialize ... ' get a long pointer to the item ... Dim Obj As Object ...
    (microsoft.public.vb.general.discussion)
  • Re: Help updating a reference table
    ... The Reference Maintenance form works fine in that I can select a Category ... Private Sub Reference_options_AfterUpdate ... won't be requeried by the code in cat lookup's AfterUpdate event procedure. ... You should still requery cat_options_lookup in cat lookup's AfterUpdate event ...
    (microsoft.public.access.gettingstarted)