By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,638 Members | 2,241 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,638 IT Pros & Developers. It's quick & easy.

saving layout of TreeView control

P: n/a
Hello,
I have a windows form with a TreeView control.
When I first open the tree all nodes are colapsed. Then, I expand some of
them and close the form.
When I call Form.showDialog() once again all nodes are collapsed again.
I would like the layout to be saved (nodes which I expanded should stay
expanded). I don't change the ImageList, Scrollable, CheckBoxes or
StateImageList properties of the control between closing and reopening the
form.

any ideas?

thanks,
--
dshemesh
Aug 15 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a

Once you close the form with the tree view, the form object and all the
objects it contained are destroyed and the memory is reused. What you could
do is write some code such that when the form is closing you save the state
of the tree view to a file like xml for example. You should keep it simple:
ie for each node in the tree check if it is expanded or collapsed and store
that in the xml file. When the form is opened, it should check this file to
see how to present the tree when it loads.

Adrian.
--
[Please mark my answer if it was helpful to you]


"dshemesh" wrote:
Hello,
I have a windows form with a TreeView control.
When I first open the tree all nodes are colapsed. Then, I expand some of
them and close the form.
When I call Form.showDialog() once again all nodes are collapsed again.
I would like the layout to be saved (nodes which I expanded should stay
expanded). I don't change the ImageList, Scrollable, CheckBoxes or
StateImageList properties of the control between closing and reopening the
form.

any ideas?

thanks,
--
dshemesh
Aug 15 '07 #2

P: n/a
I was afraid this was the only solution...
Thank you very much for the help!
--
dshemesh
"Adrian Voicu" wrote:
>
Once you close the form with the tree view, the form object and all the
objects it contained are destroyed and the memory is reused. What you could
do is write some code such that when the form is closing you save the state
of the tree view to a file like xml for example. You should keep it simple:
ie for each node in the tree check if it is expanded or collapsed and store
that in the xml file. When the form is opened, it should check this file to
see how to present the tree when it loads.

Adrian.
--
[Please mark my answer if it was helpful to you]


"dshemesh" wrote:
Hello,
I have a windows form with a TreeView control.
When I first open the tree all nodes are colapsed. Then, I expand some of
them and close the form.
When I call Form.showDialog() once again all nodes are collapsed again.
I would like the layout to be saved (nodes which I expanded should stay
expanded). I don't change the ImageList, Scrollable, CheckBoxes or
StateImageList properties of the control between closing and reopening the
form.

any ideas?

thanks,
--
dshemesh
Aug 15 '07 #3

P: n/a
Just to make sure:
When I close the form, I still hold a pointer to it, so it's not totally
destroyed. When I reopen it, I call showDialog() for the same Form instance I
closed before.
Is this still the case?
--
dshemesh
"Adrian Voicu" wrote:
>
Once you close the form with the tree view, the form object and all the
objects it contained are destroyed and the memory is reused. What you could
do is write some code such that when the form is closing you save the state
of the tree view to a file like xml for example. You should keep it simple:
ie for each node in the tree check if it is expanded or collapsed and store
that in the xml file. When the form is opened, it should check this file to
see how to present the tree when it loads.

Adrian.
--
[Please mark my answer if it was helpful to you]


"dshemesh" wrote:
Hello,
I have a windows form with a TreeView control.
When I first open the tree all nodes are colapsed. Then, I expand some of
them and close the form.
When I call Form.showDialog() once again all nodes are collapsed again.
I would like the layout to be saved (nodes which I expanded should stay
expanded). I don't change the ImageList, Scrollable, CheckBoxes or
StateImageList properties of the control between closing and reopening the
form.

any ideas?

thanks,
--
dshemesh
Aug 15 '07 #4

P: n/a

If you close the form, the pointer will point to nothing as the object will
be destroyed. What you could do however is hide the form with the Hide()
method. Later when you want to show it again just use the Show() method.

If you want however to retain the layout of the tree view even after you
close your application and turn off the computer, you can save the layout
structure in a local xml file like the example I gave earlier, otherwise if
you are not concerned about that you can just hide the form!

Adrian.
--
[Please mark my answer if it was helpful to you]


"dshemesh" wrote:
Just to make sure:
When I close the form, I still hold a pointer to it, so it's not totally
destroyed. When I reopen it, I call showDialog() for the same Form instance I
closed before.
Is this still the case?
--
dshemesh
"Adrian Voicu" wrote:

Once you close the form with the tree view, the form object and all the
objects it contained are destroyed and the memory is reused. What you could
do is write some code such that when the form is closing you save the state
of the tree view to a file like xml for example. You should keep it simple:
ie for each node in the tree check if it is expanded or collapsed and store
that in the xml file. When the form is opened, it should check this file to
see how to present the tree when it loads.

Adrian.
--
[Please mark my answer if it was helpful to you]


"dshemesh" wrote:
Hello,
I have a windows form with a TreeView control.
When I first open the tree all nodes are colapsed. Then, I expand some of
them and close the form.
When I call Form.showDialog() once again all nodes are collapsed again.
I would like the layout to be saved (nodes which I expanded should stay
expanded). I don't change the ImageList, Scrollable, CheckBoxes or
StateImageList properties of the control between closing and reopening the
form.
>
any ideas?
>
thanks,
--
dshemesh
Aug 15 '07 #5

P: n/a
ok.
Thanks!
--
dshemesh
"Adrian Voicu" wrote:
>
If you close the form, the pointer will point to nothing as the object will
be destroyed. What you could do however is hide the form with the Hide()
method. Later when you want to show it again just use the Show() method.

If you want however to retain the layout of the tree view even after you
close your application and turn off the computer, you can save the layout
structure in a local xml file like the example I gave earlier, otherwise if
you are not concerned about that you can just hide the form!

Adrian.
--
[Please mark my answer if it was helpful to you]


"dshemesh" wrote:
Just to make sure:
When I close the form, I still hold a pointer to it, so it's not totally
destroyed. When I reopen it, I call showDialog() for the same Form instance I
closed before.
Is this still the case?
--
dshemesh
"Adrian Voicu" wrote:
>
Once you close the form with the tree view, the form object and all the
objects it contained are destroyed and the memory is reused. What you could
do is write some code such that when the form is closing you save the state
of the tree view to a file like xml for example. You should keep it simple:
ie for each node in the tree check if it is expanded or collapsed and store
that in the xml file. When the form is opened, it should check this file to
see how to present the tree when it loads.
>
Adrian.
--
[Please mark my answer if it was helpful to you]
>
>
>
>
"dshemesh" wrote:
>
Hello,
I have a windows form with a TreeView control.
When I first open the tree all nodes are colapsed. Then, I expand some of
them and close the form.
When I call Form.showDialog() once again all nodes are collapsed again.
I would like the layout to be saved (nodes which I expanded should stay
expanded). I don't change the ImageList, Scrollable, CheckBoxes or
StateImageList properties of the control between closing and reopening the
form.

any ideas?

thanks,
--
dshemesh
Aug 15 '07 #6

P: n/a
dshemesh wrote:
Just to make sure:
When I close the form, I still hold a pointer to it, so it's not totally
destroyed. When I reopen it, I call showDialog() for the same Form instance I
closed before.
Is this still the case?
It depends. First, you don't hold a "pointer". You have a reference.
The reference remains valid as long as you have a variable assigned to
it. If you have custom managed data in your form class, they remain
valid as long as you keep the reference, assuming you haven't done
anything special to dispose that data (and you shouldn't have).

What may be released when the form is closed is the underlying Windows
objects (and in particular the window's handle, and the handles of any
controls in the window). This is otherwise described as disposing the form.

However, there's an exception to this: when you call Form.ShowDialog(),
closing the form does _not_ release the handles. That is, the Form is
not disposed. The main reason that this happens is so that you can
retrieve values from the controls in the form after returning from the
ShowDialog() method. But it also means that you can keep the form
around and reuse it. When using ShowDialog(), closing the form really
just hides it, just as the suggested workaround, and you can call
ShowDialog() again on the same form reference.

Hope that helps.

Pete
Aug 15 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.