TreeNode Interface

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi guys,

Don't you guys think that creating an interface for TreeNode can be of help
to programmers? The thing is that my current project involves a TreeView,
ListBoxes and a PropertyGrid. I can pass objects to both the PropertyGrid and
ListBox but I can't do that to the TreeView so we thought with my coworkers,
wouldn't it be cool to just implement an interface that will pass essential
information to the TreeView and be able to reuse the same object anywhere
else in my project? It will make the TreeView very versatile and it helps on
the encapsulation of the data.

If you want more details, just contact me.

Thanks,

humble.apprentice
 
humble.apprentice,

How would you make the TreeView acknowledge the nodes though?
 
Well, the TreeView has to check the object passed through a new overload for
the Nodes.Add() method. It will check for the methods that are inside the
object which should be the same as the ones in the interface and some others.
To get the name of the node, it should look for the ToString() method and get
the name from it. The interface should look something like this:

public interface ITreeNode
{
// Properties
String Name
{
get
{}
set
{}
}

object Tag
{
get
{}
set
{}
}

object[] Children
{
get
{}
set
{}
}
// Other methods and properties that might be required for the TreeView to
work. . .
}

So the class should look like:

class MyTreeNode : ITreeNode
{
// ITreeNode implementation and other methods
}

And the collection for this class can be something like:

class MyTreeNodeCollection : System.Collections.Generic.List<MyTreeNode>
{
...
}

If you want more ideas or information, let me know.

Yours,

humble.apprentice


Nicholas Paldino said:
humble.apprentice,

How would you make the TreeView acknowledge the nodes though?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

humble.apprentice said:
Hi guys,

Don't you guys think that creating an interface for TreeNode can be of
help
to programmers? The thing is that my current project involves a TreeView,
ListBoxes and a PropertyGrid. I can pass objects to both the PropertyGrid
and
ListBox but I can't do that to the TreeView so we thought with my
coworkers,
wouldn't it be cool to just implement an interface that will pass
essential
information to the TreeView and be able to reuse the same object anywhere
else in my project? It will make the TreeView very versatile and it helps
on
the encapsulation of the data.

If you want more details, just contact me.

Thanks,

humble.apprentice
 
Back
Top