Hi,
Sorry, me again!
I have a listview (with check box) which is populated by the programs files found in "C:\Program Files".
Please see the attachment.
If I wanted to add a search box somewhere in the window (called "main") and typed in "firefox" for example,
how could I highlight the first instance of "firefox" in the listview.
Also, how do I "move" the scroll bar down to that position?
I know Brian was asking something similar but I can't get it to work.
This is the code:
string text$="firefox"
int index = CONTROLCMD(main, Listview, @LVFINDITEM, text$)
Don't want to select it, just highlight it and move "down" to it's position.
if index <>-1
CONTROLCMD(main, Listview, @LVSETSELECTED, index)
endif
main - window name
Listview - listview name
Thanks,
Andy.
If I understand you correctly this example will show you how to accomplish your task.
NOTE: The CONTROLCMD(main, Listview, @LVFINDITEM, text$) command is internally coded to match full strings, not partials.
This example is coded to match partial strings.
'Compile as a WINDOWS target
Const LVM_FIRST = 0x1000
CONST LVM_ENSUREVISIBLE = (LVM_FIRST + 19)
Const LVM_SETEXTENDEDLISTVIEWSTYLE = (LVM_FIRST + 54)
CONST LVFI_PARTIAL = 0x8
CONST LVFI_WRAP = 0x20
CONST LVFI_STRING = 0x2
CONST LVM_FINDITEM = (LVM_FIRST + 13)
Const LVS_EX_FULLROWSELECT = 0x020
Const LVS_EX_CHECKBOXES = 0x4
TYPE LV_FINDINFO
DEF flags as UINT
DEF psz as POINTER
DEF lParam as INT
DEF pt as POINT
DEF vkDirection as UINT
ENDTYPE
window w1
int dir
pointer attrib
string filename
const LV=1
const BTN=2
const ED=3
openwindow w1,0,0,400,280,0x80C80080,0,"List view test",&handler
CONTROL w1,@LISTVIEW,"",30,24,360,158,@LVSREPORT|@LVSSORTASCENDING|@LVSSHOWSELALWAYS,LV
CONTROL w1,@BUTTON,"Find",30,200,70,20,0x50000000,BTN
CONTROL w1,@edit,"",120,200,150,20,0x50000000,ED
CONTROLCMD w1,LV,@LVINSERTCOLUMN,0,"Column1"
CONTROLCMD w1,LV, @LVSETCOLWIDTH, 0, 340
SENDMESSAGE(w1,LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_CHECKBOXES|LVS_EX_FULLROWSELECT,LV)
dir = FINDOPEN("c:\\*.*")
IF(dir)
DO
filename = FINDNEXT(dir)
CONTROLCMD w1,LV,@LVINSERTITEM,0,filename
UNTIL filename = ""
FINDCLOSE dir
endif
waituntil iswindowclosed(w1)
end
SUB handler(),int
select @MESSAGE
case @IDcreate
centerwindow w1
case @IDCONTROL
select @CONTROLID
case BTN
if @notifycode=0
string text$ = GETCONTROLTEXT (w1, ED)
LV_FINDINFO li
li.flags = LVFI_STRING|LVFI_PARTIAL|LVFI_WRAP
li.psz = text$
int pos = SendMessage(w1, LVM_FINDITEM, -1, li,LV)
CONTROLCMD(w1,LV, @LVSETSELECTED, pos)
sendmessage w1,LVM_ENSUREVISIBLE ,pos,false,LV
endif
ENDselect
case @IDCLOSEWINDOW
closewindow w1
endselect
return 0
ENDSUB
Thanks Larry,
Yes that's exactly what I am trying to do!
Will give it a go tomorrow morning and let you know.
As always, thanks very much.
Andy.
:)
Yes that's exactly what I need.
:)
Once you have found a match, is there a way to highlight the item (so it visually stands out) without placing a tick / selecting it in the check box?
Thanks,
Andy.
Quote from: andy1966 on July 04, 2013, 01:22:15 AM
Yes that's exactly what I need.
:)
Once you have found a match, is there a way to highlight the item (so it visually stands out) without placing a tick / selecting it in the check box?
Thanks,
Andy.
Sure
In the code I posted above, add a SETFOCUS line like this:
sendmessage w1,LVM_ENSUREVISIBLE ,pos,false,LV
SETFOCUS w1,lv
Perfect :)
Thanks Larry.