473,839 Members | 1,494 Online
Bytes | Software Development & Data Engineering Community
+ 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 9976
Is this a Windows or Web application? Can you construct the TreeView first
and then set Text properties from ListView data?

"Beginner" <ch*******@gmai l.com> wrote in message
news:11******** **************@ e56g2000cwe.goo glegroups.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*******@gmai l.com> wrote in message
news:11******** **************@ e56g2000cwe.goo glegroups.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 programmaticall y 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*******@gmai l.com> wrote in message
news:11******** **************@ e56g2000cwe.goo glegroups.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*******@gmai l.com> wrote in message
news:11******** **************@ e56g2000cwe.goo glegroups.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 programmaticall y 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*******@gmai l.com> wrote in message
news:11******** **************@ e56g2000cwe.goo glegroups.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*******@gmai l.com> wrote in message
news:11******** **************@ e56g2000cwe.goo glegroups.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(nodeNa me);
nodes[nodeName] = newNode;
tvView.Nodes.Ad d(newNode);
}
else
{
newNode = (TreeNode) nodes[nodeName];
}

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

if (nodes[childName] == null)
{
nodes[childName] = childNode;
newNode.Nodes.A dd(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
5536
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 is true, then prevent the current item jump to another one. In TreeView, I can set e.Cancel = true in the event BeforeSelect. However, can I do similar thing in ListView? Thanks.
0
1544
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 great, except... Private Sub tvBookmarks_BeforeSelect(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewCancelEventArgs) Handles tvBookmarks.BeforeSelect
7
10420
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, while they are added to the treeview without the path (only file name). I'd like the user would be able to remove multiple items selecting filenames from the listview. So, items should be removed both from the listview and the treeview. How can I do...
1
3745
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 (nead to get 2 columns from the table) and into the treeview (I need to get there the list of tables in the db) I don' know how to write the procedure, which would provide the data reading from the db ... I wrote one script, but it doesn't work...
0
1881
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 there are commercial options but a) I don't want to pay and b) they're all massively bloated. I want exactly a TreeList + ListView, and I want it to be kilobytes, not megabytes! :) I originally wrote one from scratch in .net 1.1, which had a few...
0
2073
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 dataadapter, populate a data set. The problem is how to use the dataset to populate a treeview. I have looked at a few examples here but none use a dataset, or the data structure was different and I could not modify to work with my data or the examples...
0
16310
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 components Add a TreeView and a ListView control to the form. Add this sample code to the form ========================== Dim con As New ADODB.Connection
0
1404
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. I want to know how to: By clicking a folder in the listview, expand and repopulate the corresponding node in the treeview. I have literally tried everything that I can think of, and I cannot get anything to work. This is for an assignment in...
1
2381
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 recommend me how i can do this, with as less delay and flicker as possible,... What are the right steps and methdods for this. What to do before clearing tree- and listview and what to do while
0
9856
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, 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...
0
10911
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, 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...
1
10654
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,...
0
10298
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 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...
0
9429
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, 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...
1
7833
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5683
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5867
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4066
muto222
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.