473,472 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Populate TreeView from ListView

Hi,

I'm trying to populate a TreeView from an existing and filled in
ListView (lvwBuild). lvwBuild is a basic two column listview which can
have any number of rows. I would like the first column of lvwBuild to
be a node and the second column to be a branch on the TreeView
(hopefully I have the syntax correct). I've been researching how to
do this but have come up empty. I'm guessing that you would fill an
array from lvwBuild and use it to populate the TreeView. However, I
have no idea how to do this in C#. Any help would be greatly
appreciated.

Thanks in advance,

Dan

Apr 7 '06 #1
6 9952
Is this a Windows or Web application? Can you construct the TreeView first
and then set Text properties from ListView data?

"Beginner" <ch*******@gmail.com> wrote in message
news:11**********************@e56g2000cwe.googlegr oups.com...
Hi,

I'm trying to populate a TreeView from an existing and filled in
ListView (lvwBuild). lvwBuild is a basic two column listview which can
have any number of rows. I would like the first column of lvwBuild to
be a node and the second column to be a branch on the TreeView
(hopefully I have the syntax correct). I've been researching how to
do this but have come up empty. I'm guessing that you would fill an
array from lvwBuild and use it to populate the TreeView. However, I
have no idea how to do this in C#. Any help would be greatly
appreciated.

Thanks in advance,

Dan

Apr 8 '06 #2
Sorry.. it is a Windows application.

Let me give a little more information... I want to fill the ListView
out first (which I have managed to do) and then click a button which
iterates through the listview and fills out the TreeView.

Thanks!

Dan

David wrote:
Is this a Windows or Web application? Can you construct the TreeView first
and then set Text properties from ListView data?

"Beginner" <ch*******@gmail.com> wrote in message
news:11**********************@e56g2000cwe.googlegr oups.com...
Hi,

I'm trying to populate a TreeView from an existing and filled in
ListView (lvwBuild). lvwBuild is a basic two column listview which can
have any number of rows. I would like the first column of lvwBuild to
be a node and the second column to be a branch on the TreeView
(hopefully I have the syntax correct). I've been researching how to
do this but have come up empty. I'm guessing that you would fill an
array from lvwBuild and use it to populate the TreeView. However, I
have no idea how to do this in C#. Any help would be greatly
appreciated.

Thanks in advance,

Dan


Apr 8 '06 #3
Is the problem with not knowing how to programmatically retrieve data from
the ListView, construct the TreeView and populate it? Nodes of the TreeView
are added using the Add method of the Nodes object.

"Beginner" <ch*******@gmail.com> wrote in message
news:11**********************@e56g2000cwe.googlegr oups.com...
Sorry.. it is a Windows application.

Let me give a little more information... I want to fill the ListView
out first (which I have managed to do) and then click a button which
iterates through the listview and fills out the TreeView.

Thanks!

Dan

David wrote:
Is this a Windows or Web application? Can you construct the TreeView
first
and then set Text properties from ListView data?

"Beginner" <ch*******@gmail.com> wrote in message
news:11**********************@e56g2000cwe.googlegr oups.com...
> Hi,
>
> I'm trying to populate a TreeView from an existing and filled in
> ListView (lvwBuild). lvwBuild is a basic two column listview which can
> have any number of rows. I would like the first column of lvwBuild to
> be a node and the second column to be a branch on the TreeView
> (hopefully I have the syntax correct). I've been researching how to
> do this but have come up empty. I'm guessing that you would fill an
> array from lvwBuild and use it to populate the TreeView. However, I
> have no idea how to do this in C#. Any help would be greatly
> appreciated.
>
> Thanks in advance,
>
> Dan
>

Apr 9 '06 #4
The problem is not knowing how to collect all the items from the
listview and transfer them to the treeview. I think I would use an
array.. but I'm not sure how to do it... or if that is the best way.

Thanks!

Dan

David wrote:
Is the problem with not knowing how to programmatically retrieve data from
the ListView, construct the TreeView and populate it? Nodes of the TreeView
are added using the Add method of the Nodes object.

"Beginner" <ch*******@gmail.com> wrote in message
news:11**********************@e56g2000cwe.googlegr oups.com...
Sorry.. it is a Windows application.

Let me give a little more information... I want to fill the ListView
out first (which I have managed to do) and then click a button which
iterates through the listview and fills out the TreeView.

Thanks!

Dan

David wrote:
Is this a Windows or Web application? Can you construct the TreeView
first
and then set Text properties from ListView data?

"Beginner" <ch*******@gmail.com> wrote in message
news:11**********************@e56g2000cwe.googlegr oups.com...
> Hi,
>
> I'm trying to populate a TreeView from an existing and filled in
> ListView (lvwBuild). lvwBuild is a basic two column listview which can
> have any number of rows. I would like the first column of lvwBuild to
> be a node and the second column to be a branch on the TreeView
> (hopefully I have the syntax correct). I've been researching how to
> do this but have come up empty. I'm guessing that you would fill an
> array from lvwBuild and use it to populate the TreeView. However, I
> have no idea how to do this in C#. Any help would be greatly
> appreciated.
>
> Thanks in advance,
>
> Dan
>


Apr 9 '06 #5
I think this may do what you need (the list view is lvwBuild, the
treeview is tbView):

Hashtable nodes = new Hashtable();

foreach (ListViewItem item in lvwBuild.Items)
{
string nodeName = item.Text;
string childName = "";
TreeNode newNode;

if (nodes[nodeName] == null)
{
newNode = new TreeNode(nodeName);
nodes[nodeName] = newNode;
tvView.Nodes.Add(newNode);
}
else
{
newNode = (TreeNode) nodes[nodeName];
}

if (item.SubItems.Count > 1)
{
childName = item.SubItems[1].Text;
TreeNode childNode = new TreeNode(childName);

if (nodes[childName] == null)
{
nodes[childName] = childNode;
newNode.Nodes.Add(childNode);
}
}

it's a long way from perfect but should give you an idea of what to do.
It's important that nodes in your listview are in the correct order, the
above code will assume that any node is hasn't seen before will be a top
level node of the treeview (tvView)

It uses a hashtable to record which tree node the listview nodes were
added to, this is the easiest way (pre .net 2.0 which has a findnode
method) to find a node, the alternative is to recurse through the whole
tree)

*** Sent via Developersdex http://www.developersdex.com ***
Apr 9 '06 #6
This is exactly what I wanted.

Thanks!!!!!!!!

Dan

Apr 11 '06 #7

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

Similar topics

4
by: alan | last post by:
Hello, Can ListView have some event just like the event BeforeSelect of TreeView? When a user try to select another item in the ListView, I would like to do some checking first. If the result...
0
by: Andre Viens | last post by:
Hello, I have a TreeView I'm using to navigate through various options shown in a ListView. I want to use the SelectedNode.Tag property to hold the items in my ListView. Everything is working...
7
by: Progalex | last post by:
Hi everybody! I have a listview and a treeview in a form . With an OpenDialog I let the user select multiple files and then these files are added to the listview with the complete pathname,...
1
by: hubertSVK | last post by:
I would like you to help me ... I'm a beginning vb.net programmer and I need an advice ... I'm creating a DB application and I need to read data from the Access table with MS Jet 4.0 into Listview...
0
by: Danny Tuppeny | last post by:
Hi all, I have a need to display a message list in the same way as Outlook Express/Thunderbird displays new posts (and probably most other newsreaders, like the one you're using now!). I know...
0
by: xmail123 | last post by:
How to populate a treeview from a dataset I am very new to C#. I need to create a Windows form that will read a SQL table and populate a treeview. I can connect to the DB, create the...
0
debasisdas
by: debasisdas | last post by:
This sample code displays employee name in the treeview control from the emp table of Scott schema in oracle database. To start with Select Microsoft windows common controls 6.0 (SP6) from...
0
by: MrColeyted | last post by:
I am designing an app that is similar to Windows Explorer. I have all working well. By clicking a directory in the treeview, the folders and files for that directory are displayed in the listview....
1
by: =?iso-8859-1?B?S2VyZW0gR/xtcvxrY/w=?= | last post by:
Hi, i am looking for a way to clear and fill a listview and right after a treeview nearly flicker and delay free. The TreeView and Listview contain Images and about 1000 Items. What can someone...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
1
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.