June 30, 2024, 05:33:20 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Treeview Question

Started by Andy, March 17, 2014, 03:51:40 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

Hi,

If I have a Treeview control, how can I get the full "path" to a child or child of child item?

e.g.

Title
  Child
   Child of Child

Child of Child when selected could send text to a static control:

Title/Child/Child of Child rather than just Child of Child

Anybody have any ideas on this?
Thanks,
Andy.

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

$include "windowssdk.inc"
$include "commctrl.inc"
autodefine "OFF"
window win
string strText
OPENWINDOW win,0,0,360,400,@MINBOX|@MAXBOX|@SIZE,0,"Treeview Demo",&winproc
   BEGINMENU win
      MENUTITLE "&File"
         MENUITEM "Quit",0,1
   ENDMENU

   CONTROL win,@TREEVIEW,"Libraries",22,22,300,300,@TVSTRACKSELECT| @TVSHASLINES|@TVSLINESATROOT|@TVSHASBUTTONS|@TVSFULLROWSELECT|@border,1
   sendmessage win,TVM_SETBKCOLOR,0,rgb(255,255,225),1
   sendmessage win,TVM_SETLINECOLOR,0,rgb(0,0,0),1
   sendmessage win,TVM_SETTEXTCOLOR,0,rgb(0,0,0),1
   def handle,handle2,handle3:INT
   handle = tvInsertItem(win , 1, "Root Group 1", 0)
      handle2 = tvInsertItem(win , 1, "Sub Group 1-1", handle)
         handle3 = tvInsertItem(win , 1, "Single Item 1-1A", handle2)
         handle3 = tvInsertItem(win , 1, "Single Item 1-1B", handle2)
         handle3 = tvInsertItem(win , 1, "Single Item 1-1C", handle2)
      handle2 = tvInsertItem(win , 1, "Sub Group 1-2", handle)
         handle3 = tvInsertItem(win , 1, "Single Item 1-2A", handle2)
         handle3 = tvInsertItem(win , 1, "Single Item 1-2B", handle2)
      handle2 = tvInsertItem(win , 1, "Sub Group 1-3", handle)
         handle3 = tvInsertItem(win , 1, "Single Item 1-3A", handle2)
      handle2 = tvInsertItem(win , 1, "Sub Group 1-4", handle)
         handle3 = tvInsertItem(win , 1, "Single Item 1-4A", handle2)
      handle2 = tvInsertItem(win , 1, "Sub Group 1-5", handle)
         handle3 = tvInsertItem(win , 1, "Single Item 1-5A", handle2)

   handle = tvInsertItem(win , 1, "Root Group 2", 0)
      handle2 = tvInsertItem(win , 1, "Sub Group 2-1", handle)   
         handle3 = tvInsertItem(win , 1, "Single Item 2-1A", handle2)
         handle3 = tvInsertItem(win , 1, "Single Item 2-1B", handle2)
      handle2 = tvInsertItem(win , 1, "Sub Group 2-2", handle)
         handle3 = tvInsertItem(win , 1, "Single Item 2-2A", handle2)
         handle3 = tvInsertItem(win , 1, "Single Item 2-2B", handle2)

sendmessage(win,TVM_EXPAND,TVE_EXPAND,handle,1)
sendmessage(win,TVM_EXPAND,TVE_EXPAND,handle2,1)
sendmessage(win,TVM_EXPAND,TVE_EXPAND,handle3,1)

waituntil win=0
end

SUB winproc(),int
   SELECT  @CLASS
      CASE @IDCLOSEWINDOW
         closewindow win
      CASE @IDCREATE
         CENTERWINDOW win
     
      CASE @IDMENUPICK     
         IF @MENUNUM=1 then closewindow win
     
         CASE @IDCONTROL
            select @CONTROLID
CASE 1:'respond to double click in treeview
IF @NOTIFYCODE = @NMDBLCLK
uint hitem = tvGetSelectedItem(win, 1)
IF hItem
tvGetItemText(win,1, hItem, strText,255)
while hItem
string tmp
hItem =sendmessage(win,TVM_GETNEXTITEM, TVGN_PARENT,hItem,1)
tvGetItemText(win,1, hItem, tmp,255)
strText = tmp+"/"+strText
wend
strText = mid$(strText, len( tmp+"/")+1)
MESSAGEBOX win,strText,"Your Selection"
ENDIF
ENDIF
            ENDselect
   ENDSELECT
RETURN 0
ENDSUB

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy

Thanks Larry,

Yes, that worked fine for me!

Thanks,
Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.