Home All Groups Group Topic Archive Search About

save treeview state and call from another form

Author
25 May 2009 1:07 PM
Co
Hi All,

As a follow up of my previous question concerning calling functions
from another form I created this:

Public Class TreeViewState
    Inherits Explorer1
    Private tt As New Dictionary(Of String, Boolean)

    Public Sub RestoreTreeViewExpandedState()

        Dim i As Integer
        For i = 0 To TreeView.Nodes.Count - 1

            If tt.ContainsKey(TreeView.Nodes(i).Name) Then

                If tt(TreeView.Nodes(i).Name) Then
                    TreeView.Nodes(i).Expand()
                Else
                    TreeView.Nodes(i).Collapse()
                End If
            End If
        Next
    End Sub

    Public Function SaveTreeState()

        Dim i As Integer

        For i = 0 To TreeView.Nodes.Count - 1

            If TreeView.Nodes(i).Nodes.Count > 0 Then
                tt.Add(TreeView.Nodes(i).Name, TreeView.Nodes
(i).IsExpanded)
            End If
        Next

        Return tt
    End Function

End Class

This class will save the status of the treeview on form Explorer1.
I want to call the functions in this class from another form,
frmZoeken:

Dim currentState As TreeViewState
currentState.SaveTreeState()
SaveQueryInTreeview()
currentUser.RestoreTreeViewExpandedState()

I get an error when I try this obect reference not set to an instance
of an object

Marco.

Author
25 May 2009 3:10 PM
Jack Jackson
On Mon, 25 May 2009 06:07:19 -0700 (PDT), Co <vonclausow***@gmail.com>
wrote:

Show quoteHide quote
>Hi All,
>
>As a follow up of my previous question concerning calling functions
>from another form I created this:
>
>Public Class TreeViewState
>    Inherits Explorer1
>    Private tt As New Dictionary(Of String, Boolean)
>
>    Public Sub RestoreTreeViewExpandedState()
>
>        Dim i As Integer
>        For i = 0 To TreeView.Nodes.Count - 1
>
>            If tt.ContainsKey(TreeView.Nodes(i).Name) Then
>
>                If tt(TreeView.Nodes(i).Name) Then
>                    TreeView.Nodes(i).Expand()
>                Else
>                    TreeView.Nodes(i).Collapse()
>                End If
>            End If
>        Next
>    End Sub
>
>    Public Function SaveTreeState()
>
>        Dim i As Integer
>
>        For i = 0 To TreeView.Nodes.Count - 1
>
>            If TreeView.Nodes(i).Nodes.Count > 0 Then
>                tt.Add(TreeView.Nodes(i).Name, TreeView.Nodes
>(i).IsExpanded)
>            End If
>        Next
>
>        Return tt
>    End Function
>
>End Class
>
>This class will save the status of the treeview on form Explorer1.
>I want to call the functions in this class from another form,
>frmZoeken:
>
>Dim currentState As TreeViewState
>currentState.SaveTreeState()
>SaveQueryInTreeview()
>currentUser.RestoreTreeViewExpandedState()
>
>I get an error when I try this obect reference not set to an instance
>of an object
>
>Marco.

This is exactly the same problem you had yesterday or the day before.
You are creating a variable (currentState) but not setting it to an
object.  Also, again you are telling us about an error but not telling
us on which line the error occurs.

Any of these will create a new object:
    Dim currentState As New TreeViewState

    Dim currentState As TreeViewState = New TreeViewState

    Dim currentState As TreeViewState
    currentState = New TreeViewState

I don't like the fact that in this class you keep referring to an
object called "TreeView".  It would be better if you added a parameter
to the New() of the TreeViewState class which is a reference to the
TreeView the class is to operate on.  That way you could use this
class for any TreeView object.
Author
25 May 2009 3:44 PM
Co
On 25 mei, 17:10, Jack Jackson <jjackson-***@cinnovations.net> wrote:
Show quoteHide quote
> On Mon, 25 May 2009 06:07:19 -0700 (PDT), Co <vonclausow***@gmail.com>
> wrote:
>
>
>
> >Hi All,
>
> >As a follow up of my previous question concerning calling functions
> >from another form I created this:
>
> >Public Class TreeViewState
> >    Inherits Explorer1
> >    Private tt As New Dictionary(Of String, Boolean)
>
> >    Public Sub RestoreTreeViewExpandedState()
>
> >        Dim i As Integer
> >        For i = 0 To TreeView.Nodes.Count - 1
>
> >            If tt.ContainsKey(TreeView.Nodes(i).Name) Then
>
> >                If tt(TreeView.Nodes(i).Name) Then
> >                    TreeView.Nodes(i).Expand()
> >                Else
> >                    TreeView.Nodes(i).Collapse()
> >                End If
> >            End If
> >        Next
> >    End Sub
>
> >    Public Function SaveTreeState()
>
> >        Dim i As Integer
>
> >        For i = 0 To TreeView.Nodes.Count - 1
>
> >            If TreeView.Nodes(i).Nodes.Count > 0 Then
> >                tt.Add(TreeView.Nodes(i).Name, TreeView.Nodes
> >(i).IsExpanded)
> >            End If
> >        Next
>
> >        Return tt
> >    End Function
>
> >End Class
>
> >This class will save the status of the treeview on form Explorer1.
> >I want to call the functions in this class from another form,
> >frmZoeken:
>
> >Dim currentState As TreeViewState
> >currentState.SaveTreeState()
> >SaveQueryInTreeview()
> >currentUser.RestoreTreeViewExpandedState()
>
> >I get an error when I try this obect reference not set to an instance
> >of an object
>
> >Marco.
>
> This is exactly the same problem you had yesterday or the day before.
> You are creating a variable (currentState) but not setting it to an
> object.  Also, again you are telling us about an error but not telling
> us on which line the error occurs.
>
> Any of these will create a new object:
>         Dim currentState As New TreeViewState
>
>         Dim currentState As TreeViewState = New TreeViewState
>
>         Dim currentState As TreeViewState
>         currentState = New TreeViewState
>
> I don't like the fact that in this class you keep referring to an
> object called "TreeView".  It would be better if you added a parameter
> to the New() of the TreeViewState class which is a reference to the
> TreeView the class is to operate on.  That way you could use this
> class for any TreeView object.

Jack,

could you please show me how this Sub New()
would look like and tell me how I can create a New object
for a Treeview which is shown on my Explorer1 form?

You know what I don't understand is why you just can't call
something which is already there. Why creating a new instance?
I mean when I create a new instance I will use that newly created
object
instead of the one already on Explorer1 form.

Marco
Author
26 May 2009 2:04 AM
James Hahn
I presume that you have used the debugger to prove that the code in LoadTree
is being executed and that the new data is being included in the query and
is appearing in the dt.Rows.Add line and you can see it in dt when the
AddNodes method is executed.  If not, then that is what you need to confirm.

If the new data is in dt and if the Select is returning the correct result
then your problem is that the line
AddNodes(TreeView.Nodes, dt.Select("ISNULL(IDParent, -1) =-1"))

is updating the wrong instance of a TreeView, and this comes back to the
core of your issues.  It seems that you may not have a clear understanding
of the distinction between classes, instances of a class, and a variables.
In particular, that variables are not the same as a class instance, that
more than one variable can refer to the same class instance, that the
instance which a variable refers to can be changed, and that a variable may
refer to no instance.  As an example, you are talking about creating an
object when I think you are actually wanting to create a reference to an
object - two very different things.

The debugging you need to do will probably come down to proving that the
AddNodes is insertng the data into the correct instance of your TreeView.

"Co" <vonclausow***@gmail.com> wrote in message
news:5a537f3d-26cd-4450-a911-fec9185bd65c@y9g2000yqg.googlegroups.com...
On 25 mei, 17:10, Jack Jackson <jjackson-***@cinnovations.net> wrote:
Show quoteHide quote
> On Mon, 25 May 2009 06:07:19 -0700 (PDT), Co <vonclausow***@gmail.com>
> wrote:
>
>
>
> >Hi All,
>
> >As a follow up of my previous question concerning calling functions
> >from another form I created this:
>
> >Public Class TreeViewState
> > Inherits Explorer1
> > Private tt As New Dictionary(Of String, Boolean)
>
> > Public Sub RestoreTreeViewExpandedState()
>
> > Dim i As Integer
> > For i = 0 To TreeView.Nodes.Count - 1
>
> > If tt.ContainsKey(TreeView.Nodes(i).Name) Then
>
> > If tt(TreeView.Nodes(i).Name) Then
> > TreeView.Nodes(i).Expand()
> > Else
> > TreeView.Nodes(i).Collapse()
> > End If
> > End If
> > Next
> > End Sub
>
> > Public Function SaveTreeState()
>
> > Dim i As Integer
>
> > For i = 0 To TreeView.Nodes.Count - 1
>
> > If TreeView.Nodes(i).Nodes.Count > 0 Then
> > tt.Add(TreeView.Nodes(i).Name, TreeView.Nodes
> >(i).IsExpanded)
> > End If
> > Next
>
> > Return tt
> > End Function
>
> >End Class
>
> >This class will save the status of the treeview on form Explorer1.
> >I want to call the functions in this class from another form,
> >frmZoeken:
>
> >Dim currentState As TreeViewState
> >currentState.SaveTreeState()
> >SaveQueryInTreeview()
> >currentUser.RestoreTreeViewExpandedState()
>
> >I get an error when I try this obect reference not set to an instance
> >of an object
>
> >Marco.
>
> This is exactly the same problem you had yesterday or the day before.
> You are creating a variable (currentState) but not setting it to an
> object. Also, again you are telling us about an error but not telling
> us on which line the error occurs.
>
> Any of these will create a new object:
> Dim currentState As New TreeViewState
>
> Dim currentState As TreeViewState = New TreeViewState
>
> Dim currentState As TreeViewState
> currentState = New TreeViewState
>
> I don't like the fact that in this class you keep referring to an
> object called "TreeView". It would be better if you added a parameter
> to the New() of the TreeViewState class which is a reference to the
> TreeView the class is to operate on. That way you could use this
> class for any TreeView object.

Jack,

could you please show me how this Sub New()
would look like and tell me how I can create a New object
for a Treeview which is shown on my Explorer1 form?

You know what I don't understand is why you just can't call
something which is already there. Why creating a new instance?
I mean when I create a new instance I will use that newly created
object
instead of the one already on Explorer1 form.

Marco
Author
26 May 2009 3:27 AM
Jack Jackson
On Mon, 25 May 2009 08:44:19 -0700 (PDT), Co <vonclausow***@gmail.com>
wrote:

Show quoteHide quote
>On 25 mei, 17:10, Jack Jackson <jjackson-***@cinnovations.net> wrote:
>> On Mon, 25 May 2009 06:07:19 -0700 (PDT), Co <vonclausow***@gmail.com>
>> wrote:
>>
>>
>>
>> >Hi All,
>>
>> >As a follow up of my previous question concerning calling functions
>> >from another form I created this:
>>
>> >Public Class TreeViewState
>> >    Inherits Explorer1
>> >    Private tt As New Dictionary(Of String, Boolean)
>>
>> >    Public Sub RestoreTreeViewExpandedState()
>>
>> >        Dim i As Integer
>> >        For i = 0 To TreeView.Nodes.Count - 1
>>
>> >            If tt.ContainsKey(TreeView.Nodes(i).Name) Then
>>
>> >                If tt(TreeView.Nodes(i).Name) Then
>> >                    TreeView.Nodes(i).Expand()
>> >                Else
>> >                    TreeView.Nodes(i).Collapse()
>> >                End If
>> >            End If
>> >        Next
>> >    End Sub
>>
>> >    Public Function SaveTreeState()
>>
>> >        Dim i As Integer
>>
>> >        For i = 0 To TreeView.Nodes.Count - 1
>>
>> >            If TreeView.Nodes(i).Nodes.Count > 0 Then
>> >                tt.Add(TreeView.Nodes(i).Name, TreeView.Nodes
>> >(i).IsExpanded)
>> >            End If
>> >        Next
>>
>> >        Return tt
>> >    End Function
>>
>> >End Class
>>
>> >This class will save the status of the treeview on form Explorer1.
>> >I want to call the functions in this class from another form,
>> >frmZoeken:
>>
>> >Dim currentState As TreeViewState
>> >currentState.SaveTreeState()
>> >SaveQueryInTreeview()
>> >currentUser.RestoreTreeViewExpandedState()
>>
>> >I get an error when I try this obect reference not set to an instance
>> >of an object
>>
>> >Marco.
>>
>> This is exactly the same problem you had yesterday or the day before.
>> You are creating a variable (currentState) but not setting it to an
>> object.  Also, again you are telling us about an error but not telling
>> us on which line the error occurs.
>>
>> Any of these will create a new object:
>>         Dim currentState As New TreeViewState
>>
>>         Dim currentState As TreeViewState = New TreeViewState
>>
>>         Dim currentState As TreeViewState
>>         currentState = New TreeViewState
>>
>> I don't like the fact that in this class you keep referring to an
>> object called "TreeView".  It would be better if you added a parameter
>> to the New() of the TreeViewState class which is a reference to the
>> TreeView the class is to operate on.  That way you could use this
>> class for any TreeView object.
>
>Jack,
>
>could you please show me how this Sub New()
>would look like and tell me how I can create a New object
>for a Treeview which is shown on my Explorer1 form?
>
>You know what I don't understand is why you just can't call
>something which is already there. Why creating a new instance?
>I mean when I create a new instance I will use that newly created
>object
>instead of the one already on Explorer1 form.
>
>Marco

If you already have an object, you use that object, you don't create a
new one.  I never said you should create a New Treeview.  As I showed
you in my previous message, the problem was with TreeViewState.  You
never initialized the currentState variable.  You either need to set
it to an existing TreeViewState object, or you need to create a new
one.
Author
26 May 2009 6:59 AM
Co
On 26 mei, 05:27, Jack Jackson <jjackson-***@cinnovations.net> wrote:
Show quoteHide quote
> On Mon, 25 May 2009 08:44:19 -0700 (PDT), Co <vonclausow***@gmail.com>
> wrote:
>
>
>
>
>
> >On 25 mei, 17:10, Jack Jackson <jjackson-***@cinnovations.net> wrote:
> >> On Mon, 25 May 2009 06:07:19 -0700 (PDT), Co <vonclausow***@gmail.com>
> >> wrote:
>
> >> >Hi All,
>
> >> >As a follow up of my previous question concerning calling functions
> >> >from another form I created this:
>
> >> >Public Class TreeViewState
> >> >    Inherits Explorer1
> >> >    Private tt As New Dictionary(Of String, Boolean)
>
> >> >    Public Sub RestoreTreeViewExpandedState()
>
> >> >        Dim i As Integer
> >> >        For i = 0 To TreeView.Nodes.Count - 1
>
> >> >            If tt.ContainsKey(TreeView.Nodes(i).Name) Then
>
> >> >                If tt(TreeView.Nodes(i).Name) Then
> >> >                    TreeView.Nodes(i).Expand()
> >> >                Else
> >> >                    TreeView.Nodes(i).Collapse()
> >> >                End If
> >> >            End If
> >> >        Next
> >> >    End Sub
>
> >> >    Public Function SaveTreeState()
>
> >> >        Dim i As Integer
>
> >> >        For i = 0 To TreeView.Nodes.Count - 1
>
> >> >            If TreeView.Nodes(i).Nodes.Count > 0 Then
> >> >                tt.Add(TreeView.Nodes(i).Name, TreeView.Nodes
> >> >(i).IsExpanded)
> >> >            End If
> >> >        Next
>
> >> >        Return tt
> >> >    End Function
>
> >> >End Class
>
> >> >This class will save the status of the treeview on form Explorer1.
> >> >I want to call the functions in this class from another form,
> >> >frmZoeken:
>
> >> >Dim currentState As TreeViewState
> >> >currentState.SaveTreeState()
> >> >SaveQueryInTreeview()
> >> >currentUser.RestoreTreeViewExpandedState()
>
> >> >I get an error when I try this obect reference not set to an instance
> >> >of an object
>
> >> >Marco.
>
> >> This is exactly the same problem you had yesterday or the day before.
> >> You are creating a variable (currentState) but not setting it to an
> >> object.  Also, again you are telling us about an error but not telling
> >> us on which line the error occurs.
>
> >> Any of these will create a new object:
> >>         Dim currentState As New TreeViewState
>
> >>         Dim currentState As TreeViewState = New TreeViewState
>
> >>         Dim currentState As TreeViewState
> >>         currentState = New TreeViewState
>
> >> I don't like the fact that in this class you keep referring to an
> >> object called "TreeView".  It would be better if you added a parameter
> >> to the New() of the TreeViewState class which is a reference to the
> >> TreeView the class is to operate on.  That way you could use this
> >> class for any TreeView object.
>
> >Jack,
>
> >could you please show me how this Sub New()
> >would look like and tell me how I can create a New object
> >for a Treeview which is shown on my Explorer1 form?
>
> >You know what I don't understand is why you just can't call
> >something which is already there. Why creating a new instance?
> >I mean when I create a new instance I will use that newly created
> >object
> >instead of the one already on Explorer1 form.
>
> >Marco
>
> If you already have an object, you use that object, you don't create a
> new one.  I never said you should create a New Treeview.  As I showed
> you in my previous message, the problem was with TreeViewState.  You
> never initialized the currentState variable.  You either need to set
> it to an existing TreeViewState object, or you need to create a new
> one.- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -

Jack,

If I understand correctly I must create a reference to the
Treeview object. Which doesn't mean I'm creating a new Treeview.
I will still use the Treeview on the Explorer1 form.

The examples you gave me create a new object:

Dim currentState As New TreeViewState
Dim currentState As TreeViewState = New TreeViewState
Dim currentState As TreeViewState
currentState = New TreeViewState

Is that creating the reference I need?
Also what would the Sub New() look like?

Marco
Author
26 May 2009 10:21 AM
Armin Zingler
Co wrote:

Show quoteHide quote
> Jack,
>
> If I understand correctly I must create a reference to the
> Treeview object. Which doesn't mean I'm creating a new Treeview.
> I will still use the Treeview on the Explorer1 form.
>
> The examples you gave me create a new object:
>
> Dim currentState As New TreeViewState
> Dim currentState As TreeViewState = New TreeViewState
> Dim currentState As TreeViewState
> currentState = New TreeViewState
>
> Is that creating the reference I need?
> Also what would the Sub New() look like?
>
> Marco

http://msdn.microsoft.com/en-us/library/2x7h1hfk.aspx


Armin
Author
26 May 2009 1:58 PM
Jack Jackson
On Mon, 25 May 2009 23:59:35 -0700 (PDT), Co <vonclausow***@gmail.com>
wrote:

Show quoteHide quote
>On 26 mei, 05:27, Jack Jackson <jjackson-***@cinnovations.net> wrote:
>> On Mon, 25 May 2009 08:44:19 -0700 (PDT), Co <vonclausow***@gmail.com>
>> wrote:
>>
>>
>>
>>
>>
>> >On 25 mei, 17:10, Jack Jackson <jjackson-***@cinnovations.net> wrote:
>> >> On Mon, 25 May 2009 06:07:19 -0700 (PDT), Co <vonclausow***@gmail.com>
>> >> wrote:
>>
>> >> >Hi All,
>>
>> >> >As a follow up of my previous question concerning calling functions
>> >> >from another form I created this:
>>
>> >> >Public Class TreeViewState
>> >> >    Inherits Explorer1
>> >> >    Private tt As New Dictionary(Of String, Boolean)
>>
>> >> >    Public Sub RestoreTreeViewExpandedState()
>>
>> >> >        Dim i As Integer
>> >> >        For i = 0 To TreeView.Nodes.Count - 1
>>
>> >> >            If tt.ContainsKey(TreeView.Nodes(i).Name) Then
>>
>> >> >                If tt(TreeView.Nodes(i).Name) Then
>> >> >                    TreeView.Nodes(i).Expand()
>> >> >                Else
>> >> >                    TreeView.Nodes(i).Collapse()
>> >> >                End If
>> >> >            End If
>> >> >        Next
>> >> >    End Sub
>>
>> >> >    Public Function SaveTreeState()
>>
>> >> >        Dim i As Integer
>>
>> >> >        For i = 0 To TreeView.Nodes.Count - 1
>>
>> >> >            If TreeView.Nodes(i).Nodes.Count > 0 Then
>> >> >                tt.Add(TreeView.Nodes(i).Name, TreeView.Nodes
>> >> >(i).IsExpanded)
>> >> >            End If
>> >> >        Next
>>
>> >> >        Return tt
>> >> >    End Function
>>
>> >> >End Class
>>
>> >> >This class will save the status of the treeview on form Explorer1.
>> >> >I want to call the functions in this class from another form,
>> >> >frmZoeken:
>>
>> >> >Dim currentState As TreeViewState
>> >> >currentState.SaveTreeState()
>> >> >SaveQueryInTreeview()
>> >> >currentUser.RestoreTreeViewExpandedState()
>>
>> >> >I get an error when I try this obect reference not set to an instance
>> >> >of an object
>>
>> >> >Marco.
>>
>> >> This is exactly the same problem you had yesterday or the day before.
>> >> You are creating a variable (currentState) but not setting it to an
>> >> object.  Also, again you are telling us about an error but not telling
>> >> us on which line the error occurs.
>>
>> >> Any of these will create a new object:
>> >>         Dim currentState As New TreeViewState
>>
>> >>         Dim currentState As TreeViewState = New TreeViewState
>>
>> >>         Dim currentState As TreeViewState
>> >>         currentState = New TreeViewState
>>
>> >> I don't like the fact that in this class you keep referring to an
>> >> object called "TreeView".  It would be better if you added a parameter
>> >> to the New() of the TreeViewState class which is a reference to the
>> >> TreeView the class is to operate on.  That way you could use this
>> >> class for any TreeView object.
>>
>> >Jack,
>>
>> >could you please show me how this Sub New()
>> >would look like and tell me how I can create a New object
>> >for a Treeview which is shown on my Explorer1 form?
>>
>> >You know what I don't understand is why you just can't call
>> >something which is already there. Why creating a new instance?
>> >I mean when I create a new instance I will use that newly created
>> >object
>> >instead of the one already on Explorer1 form.
>>
>> >Marco
>>
>> If you already have an object, you use that object, you don't create a
>> new one.  I never said you should create a New Treeview.  As I showed
>> you in my previous message, the problem was with TreeViewState.  You
>> never initialized the currentState variable.  You either need to set
>> it to an existing TreeViewState object, or you need to create a new
>> one.- Tekst uit oorspronkelijk bericht niet weergeven -
>>
>> - Tekst uit oorspronkelijk bericht weergeven -
>
>Jack,
>
>If I understand correctly I must create a reference to the
>Treeview object. Which doesn't mean I'm creating a new Treeview.
>I will still use the Treeview on the Explorer1 form.
>
>The examples you gave me create a new object:
>
>Dim currentState As New TreeViewState
>Dim currentState As TreeViewState = New TreeViewState
>Dim currentState As TreeViewState
>currentState = New TreeViewState
>
>Is that creating the reference I need?
>Also what would the Sub New() look like?
>
>Marco

That creates a new instance of TreeViewState.  I guess I don't know
what TreeViewState is.  I thought it was a stand-alone class, but now
I guess maybe it is not.  I see that it inherits from Explorer1, which
apparently is a form.  I don't understand why you would want to do
that.

I think you need to do some serious studying on how to use classes and
objects.
Author
26 May 2009 2:55 PM
Co
On 26 mei, 15:58, Jack Jackson <jjackson-***@cinnovations.net> wrote:
Show quoteHide quote
> On Mon, 25 May 2009 23:59:35 -0700 (PDT), Co <vonclausow***@gmail.com>
> wrote:
>
>
>
> >On 26 mei, 05:27, Jack Jackson <jjackson-***@cinnovations.net> wrote:
> >> On Mon, 25 May 2009 08:44:19 -0700 (PDT), Co <vonclausow***@gmail.com>
> >> wrote:
>
> >> >On 25 mei, 17:10, Jack Jackson <jjackson-***@cinnovations.net> wrote:
> >> >> On Mon, 25 May 2009 06:07:19 -0700 (PDT), Co <vonclausow***@gmail.com>
> >> >> wrote:
>
> >> >> >Hi All,
>
> >> >> >As a follow up of my previous question concerning calling functions
> >> >> >from another form I created this:
>
> >> >> >Public Class TreeViewState
> >> >> >    Inherits Explorer1
> >> >> >    Private tt As New Dictionary(Of String, Boolean)
>
> >> >> >    Public Sub RestoreTreeViewExpandedState()
>
> >> >> >        Dim i As Integer
> >> >> >        For i = 0 To TreeView.Nodes.Count - 1
>
> >> >> >            If tt.ContainsKey(TreeView.Nodes(i).Name) Then
>
> >> >> >                If tt(TreeView.Nodes(i).Name) Then
> >> >> >                    TreeView.Nodes(i).Expand()
> >> >> >                Else
> >> >> >                    TreeView.Nodes(i).Collapse()
> >> >> >                End If
> >> >> >            End If
> >> >> >        Next
> >> >> >    End Sub
>
> >> >> >    Public Function SaveTreeState()
>
> >> >> >        Dim i As Integer
>
> >> >> >        For i = 0 To TreeView.Nodes.Count - 1
>
> >> >> >            If TreeView.Nodes(i).Nodes.Count > 0 Then
> >> >> >                tt.Add(TreeView.Nodes(i).Name, TreeView.Nodes
> >> >> >(i).IsExpanded)
> >> >> >            End If
> >> >> >        Next
>
> >> >> >        Return tt
> >> >> >    End Function
>
> >> >> >End Class
>
> >> >> >This class will save the status of the treeview on form Explorer1.
> >> >> >I want to call the functions in this class from another form,
> >> >> >frmZoeken:
>
> >> >> >Dim currentState As TreeViewState
> >> >> >currentState.SaveTreeState()
> >> >> >SaveQueryInTreeview()
> >> >> >currentUser.RestoreTreeViewExpandedState()
>
> >> >> >I get an error when I try this obect reference not set to an instance
> >> >> >of an object
>
> >> >> >Marco.
>
> >> >> This is exactly the same problem you had yesterday or the day before.
> >> >> You are creating a variable (currentState) but not setting it to an
> >> >> object.  Also, again you are telling us about an error but not telling
> >> >> us on which line the error occurs.
>
> >> >> Any of these will create a new object:
> >> >>         Dim currentState As New TreeViewState
>
> >> >>         Dim currentState As TreeViewState = New TreeViewState
>
> >> >>         Dim currentState As TreeViewState
> >> >>         currentState = New TreeViewState
>
> >> >> I don't like the fact that in this class you keep referring to an
> >> >> object called "TreeView".  It would be better if you added a parameter
> >> >> to the New() of the TreeViewState class which is a reference to the
> >> >> TreeView the class is to operate on.  That way you could use this
> >> >> class for any TreeView object.
>
> >> >Jack,
>
> >> >could you please show me how this Sub New()
> >> >would look like and tell me how I can create a New object
> >> >for a Treeview which is shown on my Explorer1 form?
>
> >> >You know what I don't understand is why you just can't call
> >> >something which is already there. Why creating a new instance?
> >> >I mean when I create a new instance I will use that newly created
> >> >object
> >> >instead of the one already on Explorer1 form.
>
> >> >Marco
>
> >> If you already have an object, you use that object, you don't create a
> >> new one.  I never said you should create a New Treeview.  As I showed
> >> you in my previous message, the problem was with TreeViewState.  You
> >> never initialized the currentState variable.  You either need to set
> >> it to an existing TreeViewState object, or you need to create a new
> >> one.- Tekst uit oorspronkelijk bericht niet weergeven -
>
> >> - Tekst uit oorspronkelijk bericht weergeven -
>
> >Jack,
>
> >If I understand correctly I must create a reference to the
> >Treeview object. Which doesn't mean I'm creating a new Treeview.
> >I will still use the Treeview on the Explorer1 form.
>
> >The examples you gave me create a new object:
>
> >Dim currentState As New TreeViewState
> >Dim currentState As TreeViewState = New TreeViewState
> >Dim currentState As TreeViewState
> >currentState = New TreeViewState
>
> >Is that creating the reference I need?
> >Also what would the Sub New() look like?
>
> >Marco
>
> That creates a new instance of TreeViewState.  I guess I don't know
> what TreeViewState is.  I thought it was a stand-alone class, but now
> I guess maybe it is not.  I see that it inherits from Explorer1, which
> apparently is a form.  I don't understand why you would want to do
> that.
>
> I think you need to do some serious studying on how to use classes and
> objects.

Thank you