472,353 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

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 9828
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...
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...
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...
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...
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...
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...
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...
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...
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...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...

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.