Solved

Populating TreeView list from table

Posted on 2004-07-30
8
468 Views
Last Modified: 2013-12-26
Hi All,

I need to populate tree view from the database table.
Example Hierarchy is like this..
We have all the brokers at the top level. Under the brokers we have clients. Under the cients we have trasaction types which he deals on(cash,margin,spot etc..).

Sample Table:

BrokerCode                  Client code          TransType
=======                   =======          =======
001                              Client1                Cash
001                              Client1                Margin
001                              Client2                Margin
002                              Test                   Spot
003                              Test1                 Cash
003                              Test2                 Cash

Output should be something like this....

-- 001
       --Client1
              --Cash
              --Margin
       --Client2
              --Margin
-- 002
       --Test
              --Spot


Assume that i have all the rows in a datawindow or datastore. Please give me the code from there on.

Thanks in advance
Srinib












0
Comment
Question by:srinib
8 Comments
 
LVL 18

Expert Comment

by:diasroshan
ID: 11675961
hi,
i guess u need a new table and the format should be as follows to get a treeview....

ID         DATA    PARENTID
1      001      0
2      002      0
3      003      0
4      Client1      1
5      Client2      1
6      Test      2
7      Test1      3
8      Test2      3
9      Cash      4
10      Margin      4
12      Spot      6
13      Cash      7
14      Cash      8

i will paste the code to make the treeview... i need to write it... it might take some time coz i'm a bit tied up...

Also refer PB help..

Cheers,
Rosh
0
 
LVL 1

Author Comment

by:srinib
ID: 11691409
Please paste the code fi you have time.

Thanks for taking your valuable time.

Thanks again
Srinib
0
 
LVL 1

Author Comment

by:srinib
ID: 11691491
Please paste the code if you have time.

Thanks for taking your valuable time.

Thanks again
Srinib
0
 
LVL 2

Expert Comment

by:bluecomet
ID: 11692516
What i suggest you for performance to populate a treeview to do it level 1 by 1 if you don't need to expand all on first open event.

so in your example:

do first sql:

select id_brokercode into :li_id from "yourtable";

put in a datastore. With rowcount() you know how many you have.

go throw it with a for next

for i = 1 to ds_1.rowcount()

   tvi_item.label = "ID Broker 1"
   tvi_item.data = li_id
  // you can also put pictureindex to a picture
   tv.insertitemlast(your_handle,tvi_item)  // here your handle is 0 that is the top level
next

on every expand item you do same thing but you change your sql and the handle.


If you must have an expand all on first open event then you must do it with for in a for etc...

that's it.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:srinib
ID: 11713330
Please paste the code as per Rosh table design.

Thanks
Srinib
0
 
LVL 18

Accepted Solution

by:
diasroshan earned 50 total points
ID: 11723501
hi,

paste the following code in the constructor event of the treeview...

TreeViewItem      ltvi_Menu_Item
Long            ll_Parent_Handle,ll_Handle, ll_tvi,i
String             ls_name


tv_1.DisableDragDrop      = True

            Dw_3.SetTransObject(SQLCA)
            dw_3.Retrieve(0) // This dw is as per the table design given earlier and retrieval argument is the parentid

            
            For i = 1 to dw_3.Rowcount()
                  ls_name = dw_3.Object.datanm[i]
                  ltvi_Menu_Item.Label = ls_name
                  ltvi_Menu_Item.Data  = 0
                  ltvi_Menu_Item.pictureindex = 1
                  ltvi_Menu_Item.Selectedpictureindex = 1
                  ltvi_Menu_Item.Children      = True
                  ll_Parent_Handle = tv_1.InsertItemFirst (0,ltvi_Menu_Item)
            Next      
      //constructor code ends here...



//clicked event code goes here...      

TreeViewItem      ltvi_Menu_Item
long ll_tvi, ll_tvparent, i, ll_data
String ls_name, ls_data


ll_tvparent = tv_1.FindItem(roottreeitem!,0)
ll_tvi = tv_1.FindItem(currenttreeitem! , 0)


ll_data = tv_1.Getitem(handle,ltvi_Menu_Item)

ls_data = ltvi_Menu_Item.Label

select id into :ll_data
from test
where datanm = :ls_data;

dw_3.retrieve(ll_data)

For i = 1 To dw_3.Rowcount()      
            ls_name = dw_3.Object.datanm[i]
            ltvi_Menu_Item.Label = ls_name
            ltvi_Menu_Item.Data  = 2
            ltvi_Menu_Item.pictureindex = 2
            ltvi_Menu_Item.Selectedpictureindex = 1
//            ltvi_Menu_Item.Children      = False
//            ltvi_Menu_Item.level = 2
            tv_1.InsertItemSort (Handle,ltvi_Menu_Item)

//      tv_1.InsertItem(handle,1,ls_name,2)
Next      


// clicked code ends here...


Cheers,
Rosh
0
 
LVL 1

Author Comment

by:srinib
ID: 11724226
Yes, It is populating the tree view now.
I need small extension to this code since i am facing one minor problem here.

1) It is populating items on the first click, and also it is populating again all the items on the second click also. My aim is, it should populate only once in first click.

2) Should be able to collapse and expand the items depending on the present state.

Thanks again
Srinib
0
 
LVL 1

Expert Comment

by:sandhiyaa
ID: 11987165
reset the datawindow and retrieve the records again

regards,
sandhiya
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now