Solved

Populating TreeView list from table

Posted on 2004-07-30
8
463 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org (http://seleniumhq.org) Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

708 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

17 Experts available now in Live!

Get 1:1 Help Now