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. 3 1720 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*******@googl email.com
The address is real, but unread - please reply to the group
For VB and C# questions - tell us which version
On 2 Apr, 14:45, Larry Lard <larryl...@goog lemail.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...@googl email.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 CommentInterfac e commentInterfac e;
}
}
With my interface then looking like -
interface InterfaceCommen t
{
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.commen tInterface = person[0].???;
person[0].Comment cant be assigned to treeNode.commen tInterface since
it is returning a bool and is not a reference to its interface.
Thanks again,
Barry.
person[0].Comment cant be assigned to treeNode.commen tInterface 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 InterfaceCommen t. In this case,
person's class should implement InterfaceCommen t.
class Person : InterfaceCommen t
Now you can assign person[0] to treeNode.commen tInterface. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 NodeCollection.Contains(node) Then Return True
That function always return false.
|
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 = sText Then
Set GetNodeByText = nodEach
Exit Function
End If
Next
|
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 path "Users\Administrators\John Doe"?
Thank you in advance!
Andre Nogueira
|
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.
However, either it only add it to the root level or it only add it on level
below, doesn't matter what I select. And in some case, I just get an
exception.
|
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 may not have some
subdirectories with the same name. I am not having any problems populating
the treeview with the corresponding directory structure when switching
between radio buttons. In the treeview's AfterSelect event, I take the path
from...
| |
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 it using the IDE,
just add a treeview and some nodes and add a dropdownlist..then see if your
treeview + and - images switches and also check if your treeview
collapsed/expanded information is maintained between postbacks!
<%@ Page...
|
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 child node or a leaf node then a
DataGrid is populated based on the node's ID property. If I expand a node
then the DataGrid is not populated. This works fine. The problem is that
this doesn't work if I collapse the tree. If I collapse the tree...
|
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 TreeView is defined to has depth =3 only.
|
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
is under NodeA or NodeB. I can do this by splitting the
selectednode.fullpath of the child node but there must be a better
way.
Can any kind soul can enlighten me?
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |