473,396 Members | 1,918 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.

Adding 'object' to Treeview?


I have a bunch of related classes that I want to add into a Treeview
with a hierarchy. However, Treeview doesn't support the insertion of
the root 'object' type into the nodes, which surprises me. I just
wanted to add them in and have the mouse events fire back with the
reference to the object clicked on. I figured I'd have to override
ToString in my classes to have them show up in the treeview in the
right way and that would be that.

But to my surprise it doesn't seem to work like that and it seems like
I have to start messing with data binding... which just seems so
overkill for the task that it must be the wrong thing to do.

Can't I just add 'object' types like I can to the collection classes?
What should I be doing instead?

Thanks for any help!


Apr 6 '06 #1
4 11907
Ed,

Collections and the visual tree control are massively different
constructs.

The easiest way to do this would be to set the Tag property of the node
that refers to your object with a reference to your object.

Then, if you want to use the properties of the object in the tree, then
you can override the ToString method on your objects and display that, or
have some other common interface that they share which will give you the
description details.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ed Minrights" <no**@nospam.com> wrote in message
news:80********************************@4ax.com...

I have a bunch of related classes that I want to add into a Treeview
with a hierarchy. However, Treeview doesn't support the insertion of
the root 'object' type into the nodes, which surprises me. I just
wanted to add them in and have the mouse events fire back with the
reference to the object clicked on. I figured I'd have to override
ToString in my classes to have them show up in the treeview in the
right way and that would be that.

But to my surprise it doesn't seem to work like that and it seems like
I have to start messing with data binding... which just seems so
overkill for the task that it must be the wrong thing to do.

Can't I just add 'object' types like I can to the collection classes?
What should I be doing instead?

Thanks for any help!

Apr 6 '06 #2
On Thu, 6 Apr 2006 13:25:34 -0400, "Nicholas Paldino [.NET/C# MVP]"
<mv*@spam.guard.caspershouse.com> wrote:
Ed,

Collections and the visual tree control are massively different
constructs.

The easiest way to do this would be to set the Tag property of the node
that refers to your object with a reference to your object.

Then, if you want to use the properties of the object in the tree, then
you can override the ToString method on your objects and display that, or
have some other common interface that they share which will give you the
description details.


Cheers, I'll give that a shot. At the moment I've got the luxury of
being able to derive my classes from TreeNode and pop them directly
in. The constructor overwrites TreeNode.Text with the relevant string.

It's not ideal and it isn't going to work when I need to derive from
something else.

Apr 6 '06 #3


Cheers, I'll give that a shot. At the moment I've got the luxury of
being able to derive my classes from TreeNode and pop them directly
in. The constructor overwrites TreeNode.Text with the relevant string.
This sounds like what I am having trouble with. I have a TreeView that
works fine when I do:

Nodes.Add(new TreeNode);

but gives me an error from within TreeNode.LoadViewState when I use

Nodes.Add(new DerivedTreeNode());

defined

public class DerivedTreeNode : TreeNode
{
public DerivedTreeNode() : base()
{
Text = "Some Text";
}
}

Any clue as to what is happening?

What I really want to do is put a WebControl in the place of the TreeNode
text. I'm surprised that there isn't a simple way to do so. Or is there?
It's not ideal and it isn't going to work when I need to derive from
something else.

Apr 7 '06 #4
On Thu, 6 Apr 2006 13:25:34 -0400, "Nicholas Paldino [.NET/C# MVP]"
<mv*@spam.guard.caspershouse.com> wrote:
Ed,

Collections and the visual tree control are massively different
constructs.

The easiest way to do this would be to set the Tag property of the node
that refers to your object with a reference to your object.

Then, if you want to use the properties of the object in the tree, then
you can override the ToString method on your objects and display that, or
have some other common interface that they share which will give you the
description details.


That worked perfectly as was exactly what I was after in the first
place. I was getting a little misled by the Add method of the
TreeNodeCollection since it talks about attaching a 'key' to an entry
as well as the text.. albeit only as a String again.

Thanks very much!
Apr 13 '06 #5

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

Similar topics

0
by: Boris | last post by:
I am creating setup project for our application. Due to some reasons I need to add object file to the setup (don't ask why). So as soon as I add App.obj to Application Folder in my setup project...
0
by: Andrea | last post by:
In DNN3.2 I changed default skin file "Horizontal Menu - Fixed Width.ascx" adding: <%@ Register TagPrefix="dnn" TagName="TREEVIEWMENU" Src="~/Admin/Skins/TreeViewMenu.ascx" %> and I changed...
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...
7
by: Jonas | last post by:
Hi. I'm trying to develop a web custom control that uses a programmatically created treeview. My problem is that I get an exception when I try to render the control. With properties do I have to...
2
by: newsgroup.poster | last post by:
Hello, I'm encounterring the following problem when I try to add object datasource to my C# project: - the wizzard form open - I choose object, then click on next - the next screen display...
2
by: Luqman | last post by:
I am using VB.Net 2005 and I want to fill the Tree View with Oracle Scott/Tiger Table which contains Parent/Child keys in one table, how can I ? In VB-6, I used TreeView Key while in VB.Net 2005,...
0
by: divya1949 | last post by:
Create a windows c# application which will Read a xml file and populate nodes in the treeview. 1 On selection of treenode display the child nodes of that node in listview control 2. ...
3
by: AlFire | last post by:
Hi, Q: from the subject, why objects of old style classes are instances of 'object'? True
0
by: =?Utf-8?B?QnJpYW4gTmljaG9sc29u?= | last post by:
Hello, I've created a treeview control that gives a folder browser view of a given computer. The treeview is populated using the following methods: Protected Sub treeDst_Init(ByVal sender...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
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
tracyyun
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...

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.