1. Treeview - Selections
- Posted by Tony Steward <figjam at nlc.net.au>
Aug 22, 2000
-
Last edited Aug 23, 2000
------=_NextPart_000_000E_01C00C7D.F8208520
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
How when i use onEvent_TV can I know if the branch was selected at the =
root or not. What I am trying to do is when I select the root folder it =
opens the branch but does nothing else. When the next item is select it =
will then read from a database and fill the ListView - Hope this makes =
sence.
------=_NextPart_000_000E_01C00C7D.F8208520
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>How when i use onEvent_TV can I know if =
the branch=20
was selected at the root or not. What I am trying to do is when I select =
the=20
root folder it opens the branch but does nothing else. When the next =
item is=20
select it will then read from a database and fill the ListView - Hope =
this makes=20
------=_NextPart_000_000E_01C00C7D.F8208520--
2. Re: Treeview - Selections
------=_NextPart_000_0013_01C00C3B.B90B4060
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
>How when i use onEvent_TV can I know if the branch was selected at the =
root or not.
for this lets examine
Three level's of treeview
i.e: grandparent
______ parent
_____________ child
=20
procedure who_is_parent()
sequence classification, text, parent_name, grandparent_name
integer index, parent, grandparent, i
=20
=20
index =3D getTVIndex( TV )
=20
if index =3D 0 then
else
parent =3D 0
grandparent =3D 0
parent_name =3D {}
grandparent_name =3D {}
text =3D getTVSelectedText( TV ) -- this will be the text of item =
you selected=20
parent =3D getParent( index ) -- this will be the parent (if =
any) of the selected item
=20
if parent > 0 then -- if the item selected has a parent then
parent_name =3D getTVText( parent ) -- now we'll get the text =
(string / name) of the parent
grandparent =3D getParent( parent ) -- check to see if the above =
parent has a parent (grandparent)
if grandparent > 0 then -- if we do have one then
grandparent_name =3D getTVText( grandparent ) -- get the text =
(string / name)
end if
end if
--- Just alittle piece to let you know it works:
if parent > 0 and grandparent > 0 then
wPuts( MainWin, grandparent_name & ", " & parent_name =
& ", " & text)
elsif parent > 0 and grandparent =3D 0 then
wPuts( MainWin, parent_name & ", " & text)
elsif parent =3D 0 and grandparent =3D 0 then
wPuts( MainWin, text)
end if
end procedure
>When the next item is select it will then read from a database and fill =
the ListView -=20
if you need help with this one, right me back and I'll be glad to share =
anything I know.
euman at bellsouth.net
------=_NextPart_000_0013_01C00C3B.B90B4060
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4207.2601" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>>How when i use onEvent_TV can I =
know if the=20
branch was selected at the root or not.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial color=3D#0000ff size=3D2>for this lets =
examine</FONT></DIV>
<DIV><FONT face=3DArial color=3D#0000ff size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial color=3D#ff0000 size=3D2>Three level's of=20
treeview</FONT></DIV>
<DIV><FONT face=3DArial color=3D#ff0000 size=3D2>i.e: =
grandparent</FONT></DIV>
<DIV><FONT face=3DArial color=3D#ff0000=20
NT></DIV>
<DIV><FONT face=3DArial color=3D#ff0000=20
size=3D2> _____________ =
child</FONT></DIV>
<DIV><FONT face=3DArial color=3D#0000ff size=3D2> </FONT></DIV>
<DIV><FONT face=3DArial color=3D#0000ff size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial color=3D#0000ff size=3D2>procedure=20
who_is_parent()</FONT></DIV>
<DIV><FONT face=3DArial size=3D2><BR><FONT color=3D#0000ff>sequence =
classification,=20
text, parent_name, grandparent_name<BR>integer index, parent, =
grandparent,=20
i<BR> <BR> <BR> index =3D getTVIndex( TV=20
)<BR> <BR> if index =3D 0=20
then<BR> else</FONT></FONT></DIV>
<DIV><FONT face=3DArial color=3D#0000ff size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial color=3D#0000ff size=3D2> =
parent =3D=20
0<BR> grandparent =3D 0</FONT></DIV>
<DIV><FONT color=3D#0000ff></FONT> </DIV>
<DIV><FONT face=3DArial color=3D#0000ff size=3D2> =
parent_name =3D=20
{}<BR> grandparent_name =3D {}</FONT></DIV>
<DIV><FONT color=3D#0000ff></FONT> </DIV>
<DIV><FONT face=3DArial color=3D#0000ff size=3D2> text =
=3D=20
getTVSelectedText( TV ) <FONT color=3D#ff0000>-- this will be the text =
of item you=20
selected</FONT> <BR> parent =3D getParent( index=20
) <FONT color=3D#ff0000>-- this will =
be the=20
parent (if any) of the selected=20
item</FONT><BR> <BR> if parent > 0=20
then <FONT color=3D#ff0000>-- if the item selected has a =
parent=20
then</FONT><BR> parent_name =3D getTVText( parent ) =
<FONT=20
color=3D#ff0000>-- now we'll get the text (string / name) of the=20
parent<BR></FONT> grandparent =3D getParent( parent=20
) <FONT color=3D#ff0000>-- check to see if the above =
parent has a=20
parent =
(grandparent)<BR></FONT> if=20
grandparent > 0 then <FONT color=3D#ff0000>-- if we do have one=20
p;=20
grandparent_name =3D getTVText( grandparent ) <FONT color=3D#ff0000>-- =
get the=20
text</FONT> <FONT color=3D#ff0000>(string /=20
name)</FONT><BR> end=20
if<BR> end if<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><FONT color=3D#ff0000>--- Just alittle =
piece to let=20
you know it works:</FONT></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><FONT =
color=3D#ff0000></FONT> </DIV></FONT>
<DIV><FONT face=3DArial color=3D#0000ff size=3D2> if =
parent > 0=20
and grandparent > 0=20
; =20
wPuts( MainWin, grandparent_name & ", " & parent_name & ", " =
&=20
text)<BR> elsif parent > 0 and grandparent =3D 0=20
; =20
wPuts( MainWin, parent_name & ", " & =
text)<BR> =20
elsif parent =3D 0 and grandparent =3D 0=20
; =20
wPuts( MainWin, text)<BR> end =
if<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><FONT color=3D#0000ff>end=20
procedure</FONT></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><FONT =
color=3D#0000ff></FONT></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>>When the next item is select it =
will then read=20
from a database and fill the ListView - </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial color=3D#0000ff size=3D2>if you need help with =
this one, right=20
me back and I'll be glad to share anything I know.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><A=20
------=_NextPart_000_0013_01C00C3B.B90B4060--
3. Re: Treeview - Selections
From: Tony Steward
>How when i use onEvent_TV can I know if the branch was selected at the root
or not. What I am >trying to do is when I select the root folder it opens
the branch but does nothing else. When the >next item is select it will then
read from a database and fill the ListView - Hope this makes >sence.
This message, and one from Rob Verbruggen, made me go back and look at this
issue. For some reason, I overlooked onChange when I originally wrote this.
Clearly, that's how this should work. I'll have this fixed in the next
release. It's an easy fix, though. In WndProc, find this line:
elsif iMsg = TVN_SELCHANGED then
Just comment out (or delete the stuff about onEvent):
--if onEvent[id] != -1 then
-- result = { fetch( lParam, NMTREEVIEW_itemOldlParam ),
-- fetch( lParam, NMTREEVIEW_itemNewlParam ) }
-- call_proc( onEvent[id], { TVN_SELCHANGED,
-- result[1], result[2] } )
--end if
And add:
if onChange[id] != -1 then
call_proc( onChange[id], {} )
end if
This will change your code slightly. First, you'll need to use getIndex
within your onChange proc to figure out which item has been selected.
Matt
PS I sent Tony a private reply showing him how to do what he was asking
about. It's basically straight from my ListTreeView.exw demo. Here's what
I told him:
--Begin original reply
First, in order to determine if you're at the root, you'll want to use
getParent (the item being selected when an onTVSelect event is sent is given
by lParam). If the return is 0, you'll know you've got a root item. To
expand, you'll need the handle to the treeview item. This is something that
should really be wrapped within win32lib. Put the following code in
win32lib:
global procedure expandItem( integer id, integer item )
integer ok
ok = sendMessage( id , TVM_EXPAND, TVE_EXPAND, tvitem_handle[item] )
end procedure
So, in your code, your onEvent_tv code will look something like:
procedure onEvent_TV( atom event, atom wParam, atom lParam )
atom ix
if event = onTVSelect then
-- delete items in listview LV
if deleteItem( LV, -1 ) then end if
-- check to see if this is the root
if getParent(id) then
-- your code to fill the listview goes here
else
expandItem( getSelf(), lParam )
end if
end if
end procedure
--End original reply