473,385 Members | 1,355 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

saving layout of TreeView control

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
6 3198

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
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
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

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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: SoKool | last post by:
Can anyone point me to a site where I can get a free treeview control to use in ASP .NET or any tutorial that can help me build my own treeview control. I intend to use a treeview to generate a...
1
by: Hrvoje Voda | last post by:
How can I check if the parent root is "Opened"? I mean if a user has expand the treeview and he can see the child root ? Hrcko
8
by: Hrvoje Voda | last post by:
What is wrong in this code? private void tree_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { if (e.KeyCode == Keys.Enter ) {
3
by: Peter | last post by:
Hello, We are inserting a side menu to our application using a class that is writing HTML on all our pages. This is a part of the code as an example: writer.Write(" <table WIDTH=""100%""...
4
by: Ben Coats | last post by:
Hey, I'm trying to find code for an Explorer-style Directory ComboBox. (You know, it display "Desktop", "My Computer", all drives, etc., but it has a treeview control inside the combobox so that...
10
by: p3t3r | last post by:
I have a treeview sourced from a SiteMap. I want to use 2 different CSS styles for the root level nodes. The topmost root node should not have a top border, all the other root nodes should have a...
1
by: musosdev | last post by:
Hi guys I was using the Microsoft.Web.UI.WebControls extra namespace in my application to provide me with a TreeView control. I was using specifically ..GetNodeFromIndex(), SelectedNodeIndex and...
1
by: garyusenet | last post by:
Hi All, I'm eagerly anticipating what you have to say on something that's stumped me over the weekend. I'm writing a small application which utilises a treeview control. I've figured out how to...
1
micmast
by: micmast | last post by:
Ey all, I'm currently working on an application that uses the pygtk libraries to create windows and widgets. I have a HBOX (2 boxes) in the middle and in the left one I have a treeview, in the...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.