473,396 Members | 1,748 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,396 software developers and data experts.

Associating a set function with a TreeView Node

Hi,

Lets say I have a TreeView with nodes that represent objects of a
number of different types. Is there a way of associating the Set
method of each object with its node in the TreeView? That way when you
select a node in order to change its associated data, you have easy
access to its Set function.

The way I normally handel this situation is is to create an enum of
all the different types that the treeview contains. I then have a
string table which corresponds to each member of the enum. I can then
use these to set the Name member of each Node and hence establish from
that which type I'm working with.

I'm guessing there is an easier way of doing this...

Thanks,

Barry.

Apr 2 '07 #1
3 1701
bg***@yahoo.com wrote:
Hi,

Lets say I have a TreeView with nodes that represent objects of a
number of different types. Is there a way of associating the Set
method of each object with its node in the TreeView? That way when you
select a node in order to change its associated data, you have easy
access to its Set function.

The way I normally handel this situation is is to create an enum of
all the different types that the treeview contains. I then have a
string table which corresponds to each member of the enum. I can then
use these to set the Name member of each Node and hence establish from
that which type I'm working with.

I'm guessing there is an easier way of doing this...
Two approaches spring to mind:

- If all these objects have a Set method*, then pull that method out
into an ISettable interface that they all then implement. Then have each
TreeNode hold** a reference to an object of type ISettable which it can
use to get at its ISettable.

- If the objects 'setting' behaviour isn't uniform, define a delegate
type (from void to void, or whatever), then in the TreeNode hold** a
delegate to the object's DoWhatever method.

* If 'Set' is just an example, OK, but if not then it's stylsitically
not a very nice name for a method.

** Two ways to make a TreeNode hold an arbitrary extra piece of
information: lazy + dirty, use the Tag property; clean and not much more
work, derive from TreeNode a TreeNodeEx class that holds whatever
(strongly typed) extra information you need.
--
Larry Lard
la*******@googlemail.com
The address is real, but unread - please reply to the group
For VB and C# questions - tell us which version
Apr 2 '07 #2
On 2 Apr, 14:45, Larry Lard <larryl...@googlemail.comwrote:
b...@yahoo.com wrote:
Hi,
Lets say I have a TreeView with nodes that represent objects of a
number of different types. Is there a way of associating the Set
method of each object with its node in the TreeView? That way when you
select a node in order to change its associated data, you have easy
access to its Set function.
The way I normally handel this situation is is to create an enum of
all the different types that the treeview contains. I then have a
string table which corresponds to each member of the enum. I can then
use these to set the Name member of each Node and hence establish from
that which type I'm working with.
I'm guessing there is an easier way of doing this...

Two approaches spring to mind:

- If all these objects have a Set method*, then pull that method out
into an ISettable interface that they all then implement. Then have each
TreeNode hold** a reference to an object of type ISettable which it can
use to get at its ISettable.

- If the objects 'setting' behaviour isn't uniform, define a delegate
type (from void to void, or whatever), then in the TreeNode hold** a
delegate to the object's DoWhatever method.

* If 'Set' is just an example, OK, but if not then it's stylsitically
not a very nice name for a method.

** Two ways to make a TreeNode hold an arbitrary extra piece of
information: lazy + dirty, use the Tag property; clean and not much more
work, derive from TreeNode a TreeNodeEx class that holds whatever
(strongly typed) extra information you need.

--
Larry Lard
larryl...@googlemail.com
The address is real, but unread - please reply to the group
For VB and C# questions - tell us which version- Dölj citerad text -

- Visa citerad text -
Cool, thanks very much for your help Larry. I still have one remaining
problem though.

Each object, represented as a node in the TreeView, has a member
called "comment". So I've decided to begin here. My TreeNodeEx class
is as follows -

namespace MyApplication
{
class TreeNodeEx : TreeNode
{
public CommentInterface commentInterface;
}
}

With my interface then looking like -

interface InterfaceComment
{
string Comment
{
get;
set;
}
}

Which my objects then implement.

Now I create a TreeNodeEx object as follows -

TreeNodeEx treeNode = new TreeNodeEx();
treeNode.Text = person[0].Name;

But how do I set the interface?

treeNode.commentInterface = person[0].???;

person[0].Comment cant be assigned to treeNode.commentInterface since
it is returning a bool and is not a reference to its interface.

Thanks again,

Barry.

Apr 2 '07 #3
person[0].Comment cant be assigned to treeNode.commentInterface since
it is returning a bool and is not a reference to its interface.
I'm assuming that you meant that person[0].Comment is returning a
string rather than a bool....

You need a concrete implementation of InterfaceComment. In this case,
person's class should implement InterfaceComment.

class Person : InterfaceComment

Now you can assign person[0] to treeNode.commentInterface.

Apr 3 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: serge calderara | last post by:
Dear all, I am populating a treeview control with an XML file. I need to skip duplicate node entry from XML file in treeview if exit For that I ma using the following line of code : If...
1
by: Ivan Abramov | last post by:
I have such one written in VB6. Public Function GetNodeByText(colNodes As Nodes, sText As String) As Node Dim nodEach As Node, nodResult As Node For Each nodEach In colNodes If nodEach.Text =...
13
by: André Nogueira | last post by:
Hi there. I know you can view a node's fullpath property, but is it posible to select a node using its path? Like, tell the treeview that the node that should be selected is the node with the...
6
by: L.M | last post by:
Hello, I knew how to use the treeview under VB6. After migrating to .NET, well, I'm lost. I try to add a new node, either to the same level or as a child to a selected node in the treeview....
0
by: Treeview Trouble | last post by:
I have an application where there are two radio buttons each of which populates a treeview control with a directory structure. Each radio button corresponds to a different directory which may or...
1
by: Alex D. | last post by:
hey guys I found what is causing the problems with my treeview in Firefox...the answer is: treeview+dropdwonlist in the same page dont work! try this simple code and see for yourselves. you can do...
3
by: Shawn | last post by:
Hi. I'm working with the TreeView control in my ASP.NET 1.1 application. I have a problem I haven't been able to figure out. When I click on a node (not expand), whether it's a parent node, a...
0
by: jiing | last post by:
Hi all, I want to use sting(the same as Node.Text) to judge if a node exists in TreeView. I've tried several ways, but seems all failed. could anybody help me? Thanks in advance. //My...
6
by: xla76 | last post by:
I have a simple treeview (treeview1) to which I have added two nodes (nodeA and nodeB) which have n levels of child nodes. What I want is to be able to identify whether the child node I select...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.