Link to home
Start Free TrialLog in
Avatar of srinib
srinib

asked on

Populating TreeView list from table

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












Avatar of diasroshan
diasroshan
Flag of Kuwait image

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
Avatar of srinib
srinib

ASKER

Please paste the code fi you have time.

Thanks for taking your valuable time.

Thanks again
Srinib
Avatar of srinib

ASKER

Please paste the code if you have time.

Thanks for taking your valuable time.

Thanks again
Srinib
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.
Avatar of srinib

ASKER

Please paste the code as per Rosh table design.

Thanks
Srinib
ASKER CERTIFIED SOLUTION
Avatar of diasroshan
diasroshan
Flag of Kuwait image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of srinib

ASKER

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
reset the datawindow and retrieve the records again

regards,
sandhiya