 |
|
 |
Short & Simple, love it! Thanks.
|
|
|
|
 |
|
 |
Hello!
First of all thanks a lot for this code, but actually, using this I found out that I can save stateimageindex using this code. Could you please help me with this or just give me some pieces of advice?
|
|
|
|
 |
|
 |
Hi Mr. Nothing
I am now since approx. 5 years only writing Java and I am no longer working with C#.
Because I am interested in many languages this was just my preferred one as I wrote the article.
I could imagine you have to cast your 'stateimageindex' to a object variable first so
it can be serialized - if it is an primitive type this may not work...
But this is just a suggestion.
In Java, Perl oder Objective-C what I am currently using, most of the
time I just don't want to serialize any data because I like human readable XML files
All the best!
Regards, Joerg
|
|
|
|
 |
|
 |
Hi your code worked just great - thanks a ton! I made a small modification for my use as my tree is quite small and is fine to be stored in the registry. Here it is... in case its useful to anyone.
Here's the use case:
<pre>
private void cmdSave_Click(object sender, EventArgs e)
{
MemoryStream str = new MemoryStream();
TreeViewPersist.SaveTree(treeView1, str);
Application.UserAppDataRegistry.SetValue("TREEDATA", str.ToArray());
}
private void LoadData()
{
var val = (byte[])Application.UserAppDataRegistry.GetValue("TREEDATA");
if (val != null)
{
MemoryStream str = new MemoryStream(val);
TreeViewPersist.LoadTree(treeView1, str);
}
}
</pre>
For the implementation, I just overloaded existing methods and isolated the stream part, for example.
<code>
public static int SaveTree(TreeView tree, string filename)
{
Stream file = null;
try
{
// Datei anlegen
file = File.Open(filename, FileMode.Create);
return SaveTree(tree, file);
}
finally
{
if (file != null)
file.Close();
}
}
..
public static int SaveTree(TreeView tree, Stream output)
{
use output instead of original stream
}
</code>
I think its simple enough. I can mail the complete source code on request.
I have miles to code before I sleep
|
|
|
|
 |
|
 |
Congrats!
|
|
|
|
 |
|
 |
Hi,
Its a nice work.But I have a problem while saving my tree into a file.
From my tree( a wsdl file in tree structure) I cant save it to a WSDL file.
Though it is serialised data is not in the text format.
Can anyone help me please.
Thanks in advance...
|
|
|
|
 |
|
 |
I don't know how to implement this in my project.
can you please help me?
thx
|
|
|
|
 |
|
 |
Hello there ...
I am not into C# Programming at the moment - since some years I got the focus on Java.
What exactly is your question ? Where is the problem ?
Regards, JH
|
|
|
|
 |
|
 |
Thanks for your Article.
It was very much help for me in my Project.
|
|
|
|
 |
|
 |
I have an question.
I am using 'DataGridViewRow' array private object in my Class1 & I am saving the object of Class1 in the Tag of TreeNodes of treeView1. But When I am tring to save my treeView1 in File using saveTree() , it is giving me error that 'DataGridViewRow is not marked as Serializable'.
So what should I do to use DataGridViewRow in Tag object?
-- modified at 0:22 Wednesday 29th November, 2006
|
|
|
|
 |
|
 |
Hi, Thanks for this - really helped my project!!!
|
|
|
|
 |
|
 |
When I save my treeview to arraylist, your code can't save childnode.
Right?
Help me. I hope copy one treeview nodes to other treeview.
Thanks.
|
|
|
|
 |
|
 |
Hannemann ,
Thanks for the great code. It really helped me kick start my project. Props.
P
|
|
|
|
 |
|
 |
First of all let me just say that this is exactly what i was looking for.
now, i noticed that if you add to treeview this:
- item
- item
- item
( 1 subitem with another subitem with the same name )
then, when loading, it looks like this:
- item
- item
- item
(2 subs!!!)
the problem is with the searchNode().
the thing is that i have not found a soultion...
PLEASE responed...
|
|
|
|
 |
|
 |
Hi Lior ...
as you know ( ) .. the Bug is now fixed !
I did some improvements .. the result is a better and shorter code.
Regards, JH
|
|
|
|
 |
|
 |
Although the code is useful and fills the gap of TreeView state serialization, I would recommend to :
- use the built-in TreeNode serialization, namely :
private virtual void System.Runtime.Serialization.ISerializable.GetObjectData(SerializationInfo si, StreamingContext context) {
if (this.propBag != null)
si.AddValue("PropBag", typeof(OwnerDrawPropertyBag));
si.AddValue("Text", this.text);
si.AddValue("IsChecked", this.isChecked);
si.AddValue("ImageIndex", this.imageIndex);
si.AddValue("SelectedImageIndex", this.selectedImageIndex);
si.AddValue("children", this.children, typeof(System.Windows.Forms.TreeNode[]));
if (this.userData != null && this.userData.GetType().IsSerializable)
si.AddValue("UserData", this.userData, this.userData.GetType());
}
- implement the ISerializable interface at the TreeView level (essentially recursively calling the mentioned TreeNode serialization method), so that it uses the standard .NET serialization "protocol".
|
|
|
|
 |
|
 |
Hi.
That looks fine...
but I don't think that I am able to use your code.
I did not knew that there is a built-in TreeNode serialization.
Could you give a shot example how I can use your code ?
|
|
|
|
 |
|
 |
- for the TreeNode, the GetObjectData is what is called by the CLR when you do a formatter.Serialize(stream, node);
- for the TreeView, you've got to add the [Serializable] attribute, inherit ISerializable, and provide implementation for GetObjectData. For instance :
[Serializable]
public class MyObject : ISerializable
{
public int n1;
public int n2;
public String str;
public MyObject()
{
}
protected MyObject(SerializationInfo info, StreamingContext context)
{
n1 = info.GetInt32("i");
n2 = info.GetInt32("j");
str = info.GetString("k");
}
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("i", n1);
info.AddValue("j", n2);
info.AddValue("k", str);
}
}
|
|
|
|
 |
|
 |
Hi.
I looked into the .NET Help and there is another example for that.
I will try to do it that way, even if I am not really sure how it
works and how I can use it with a TreeNode and what my new class,
that I have to write, has to implement.
Maybe I will have to ask you again .. because a more elegant and
well-coded solution is always interesting for me.
|
|
|
|
 |
|
 |
You are welcome to post on this topic since, as you know, it is a recurrent topic in dev forums and it will be greatly appreciated by many of us.
-- modified at 10:12 Wednesday 12th October, 2005
|
|
|
|
 |
|
 |
OK, how'd you do the dancing banana, or is it a trade secret?
Marc
Help! I'm an AI running around in someone's f*cked up universe simulator. Sensitivity and ethnic diversity means celebrating difference, not hiding from it. - Christian Graus Every line of code is a liability - Taka Muraoka Microsoft deliberately adds arbitrary layers of complexity to make it difficult to deliver Windows features on non-Windows platforms--Microsoft's "Halloween files"
|
|
|
|
 |
|
 |
Sorry for the post that does not belong, but I had to try it!
Jerry
|
|
|
|
 |
|
 |
Oh great. Now there's two of you. I'll right. I'll give it a shot.
:banana:
:bananas:
:dancingbanana:
(This is probably of more value than this article, you know).
[edit]Phooey.[/edit]
[edit]YES!!![/edit]
Marc
Help! I'm an AI running around in someone's f*cked up universe simulator. Sensitivity and ethnic diversity means celebrating difference, not hiding from it. - Christian Graus Every line of code is a liability - Taka Muraoka Microsoft deliberately adds arbitrary layers of complexity to make it difficult to deliver Windows features on non-Windows platforms--Microsoft's "Halloween files"
|
|
|
|
 |