 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Bartimus
Joined: 10 Nov 2005 Posts: 164 Location: Texas
|
Posted: Mon Feb 08, 2010 7:28 pm Post subject: Selecting a LISTVIEW item |
|
|
I'm not figuring out how to have AHK select a line in a LISTVIEW automatically. Basically I'm looking for a way for AHK to read from an INI file of a previously selected entry (which is written to on a previous use of the AHK) then automatically highlight/select that same entry.
Can anyone help? |
|
| Back to top |
|
 |
Leef_me
Joined: 08 Apr 2009 Posts: 5336 Location: San Diego, California
|
Posted: Mon Feb 08, 2010 11:50 pm Post subject: |
|
|
Selecting the row is slightly less intuitive than some might hope.
You do it by modifying the row:
LV_Modify(RowNumber, "-Select") ; deselect
LV_Modify(RowNumber, "+Select") ; select
http://www.autohotkey.com/docs/commands/ListView.htm#bifRow
Row Functions
LV_Modify(RowNumber, Options [, NewCol1, NewCol2, ...]):
Row Options: The Options parameter is a string containing zero or more words from the list below (not case sensitive). Separate each word from the next with a space or tab. To remove an option, precede it with a minus sign. To add an option, a plus sign is permitted but not required. |
|
| Back to top |
|
 |
Bartimus
Joined: 10 Nov 2005 Posts: 164 Location: Texas
|
Posted: Tue Feb 09, 2010 6:19 am Post subject: |
|
|
But how do I know what the row number is for a specific... say file?
Like I use my script and select a file in the script. before executing the file, the script writes to an ini file of what we executed then the script exits.
Later, I want to start the script and it read the ini file, finding the last file I executed and select (incase I want to execute it again and I forgot which I had selected previously).
I can't count that there will be exactly the same number of items in the listview or that it will always contain the same information in the same order. |
|
| Back to top |
|
 |
garry
Joined: 19 Apr 2005 Posts: 2214 Location: switzerland
|
Posted: Tue Feb 09, 2010 10:19 am Post subject: |
|
|
2 Listview, see contents from last selected file
| Code: | MODIFIED=20100210
;-- LV_Modify(RFB, "Vis") ; scrollto row visible aera
;-- see last selected file (doubleclick saves to inifile)
setworkingdir,%A_scriptdir%
R3C=%A_scriptdir%\CSVFILES
ifnotexist,%R3C%
{
FileCreateDir,%R3C%
Fileappend,test1_aaa1`;aaa1`r`n,%R3C%\test1.csv
Fileappend,test1_aaa2`;aaa2`r`n,%R3C%\test1.csv
Fileappend,test2_bbb1`;bbb1`r`n,%R3C%\test2.csv
Fileappend,test2_bbb2`;bbb2`r`n,%R3C%\test2.csv
Fileappend,test3_ccc1`;ccc1`r`n,%R3C%\test3.csv
Fileappend,test3_ccc2`;ccc2`r`n,%R3C%\test3.csv
}
RSSINI=%A_scriptdir%\RSSINI.txt
gosub,iniread11
Gui,2:Add, ListView, backgroundGray cWhite grid x5 y0 h250 w300 +hscroll altsubmit vLB1 gLB , CSV1
Gui,2:Add, ListView, backgroundTeal cWhite grid x310 y0 h250 w300 +hscroll altsubmit vA1 gLW2, A|B
gosub,FilllistviewB1
gosub,FilllistviewA1
Gui,2:Show,x0 y0 w620 h300,TEST33
return
;-------------------------------------------------------------------
;==================== INIREAD LASTSELECTED ========================
INIREAD11:
IniRead, R3BB , %rssini% ,LASTSELECTEDXX , KEY4
SplitPath,R3BB, namex, dir, ext, name_no_ext, drive
return
;-------------------------------------------------------------------
;==================== LV_LEFT show *.csv and mark the file lastselected.csv ===================
FillListViewB1:
Gui,2:Submit,nohide
Gui,2:Default
Gui,2:Listview,LB1
LV_Delete()
LV_ModifyCol(1,280)
loop,%R3C%\*.csv
{
FX=%A_LoopFileName%
stringlen,L1,FX
stringmid,FA,FX,1,L1-4
LV_Add("",FA)
}
LV_ModifyCol(1, "Sort")
searchedfile=%name_no_ext%
LV_Modify(RFB, "-Select -Focus")
RFB:=0
loop, % LV_GetCount()
{
RFB:=(RFB+1)
LV_GetText(CKL,RFB,1)
ifinstring,CKL,%searchedfile%
{
LV_Modify(RFB, "+Select +Focus")
break
}
}
LV_Modify(RFB, "Vis") ; scrollto row visible aera
R3X=%R3C%\%CKL%.csv
return
;--------------------
FilllistviewA1:
Gui,2:Submit,nohide
Gui,2:Default
Gui,2:Listview,A1
LV_Delete()
LV_ModifyCol(1,140)
LV_ModifyCol(2,140)
loop,read,%R3X%
{
I++
BX1=
BX2=
stringsplit,BX,A_LoopReadLine,`;,
LV_Add("",BX1,BX2)
}
LV_ModifyCol(1, "Sort")
return
;--------------------
2GuiClose:
exitapp
;--------------------
;---- LV_LEFT-------
LB:
Gui,2:Submit,nohide
Gui,2:Default
Gui,2:Listview,LB1
RNB:=LV_GetNext("C") ;2 selected checked
RFB:=LV_GetNext("F") ;2 selected focused
GCB:=LV_GetCount() ;4 total
if A_GuiEvent=normal
{
LV_GetText(C1,A_eventinfo,1)
R3X=%R3C%\%C1%.csv
gosub,FilllistviewA1
return
}
if A_GuiEvent=doubleclick
{
LV_GetText(C1,A_eventinfo,1)
R3X=%R3C%\%C1%.csv
IniWrite,%r3x% , %rssini% ,LASTSELECTEDXX , KEY4
run,%r3x%
}
return
;===============================================================
LW2:
Gui,2:Submit,nohide
Gui,2:Default
Gui,2:Listview,A1
if A_GuiEvent = Normal
{
C1=
C2=
LV_GetText(C1,A_EventInfo,1)
LV_GetText(C2,A_EventInfo,2)
msgbox,C1=%c1%`nC2=%c2%
}
return
;===============================================================
|
Last edited by garry on Wed Feb 10, 2010 6:17 am; edited 1 time in total |
|
| Back to top |
|
 |
Bartimus
Joined: 10 Nov 2005 Posts: 164 Location: Texas
|
Posted: Tue Feb 09, 2010 5:26 pm Post subject: |
|
|
Garry... Thank for post. Your script is probably a little bit over the top for me, but I tried to work it out. I've took your idea and kinda changed it up.
I still can't get it to work though. | Code: | IniRead, LastFile, %DrvLtr%:\Portable\FileDirCfg.ini, LastFile, Viewing , 0
Loop, %DrvLtr%:\Portable\*.*
{
LV_Add("", A_LoopFileName)
if (LastFile = A_LoopFileName)
{
SelectRow := A_Index
TrayTip, File Directory, Last File was %LastMovie%`nfound at Row #%SelectRow%
}
}
WinActivate, Video Directory
LV_Modify(%SelectRow%, "+Select +Focus") ; select |
The IF statment successfully fires off and SELECTROW variable gets a value, and the TRAYTIP shows this, but that's it. |
|
| Back to top |
|
 |
garry
Joined: 19 Apr 2005 Posts: 2214 Location: switzerland
|
Posted: Tue Feb 09, 2010 7:39 pm Post subject: |
|
|
hello Bartimus
this script searches in (E) %DrvLtr%:\Portable\*.*
when doubleclick starts (exe etc.. ) and write last selected name
when script new start see last selected file
| Code: |
MODIFIED=20100210
;-- LV_Modify(RFB, "Vis") ; scrollto row visible aera
DrvLtr=E ;searches in (E) %DrvLtr%:\Portable\*.*
setworkingdir,%A_scriptdir%
RSSINI=%A_scriptdir%\RSSINI.txt
gosub,iniread11
Gui,2:Add, ListView, backgroundTeal cWhite grid x10 y0 h250 w300 +hscroll altsubmit vA1 gLW2, A|B
gosub,FilllistviewA1
Gui,2:Show,x0 y0 w320 h300,TEST33
return
;-------------------------------------------------------------------
;==================== INIREAD LASTSELECTED ========================
INIREAD11:
IniRead, R3X , %rssini% ,LASTSELECTEDXX , KEY4
SplitPath,R3X, namex, dir, ext, name_no_ext, drive
return
;-------------------------------------------------------------------
FilllistviewA1:
Gui,2:Submit,nohide
Gui,2:Default
Gui,2:Listview,A1
LV_Delete()
LV_ModifyCol(1,280)
LV_ModifyCol(2,0)
Loop, %DrvLtr%:\Portable\*.*
LV_Add("", A_LoopFileName,A_LoopFileFullPath)
LV_ModifyCol(1, "Sort")
searchedfile=%R3X%
LV_Modify(RFB, "-Select -Focus")
RFB:=0
loop, % LV_GetCount()
{
RFB:=(RFB+1)
LV_GetText(CKL,RFB,1)
ifinstring,CKL,%searchedfile%
{
LV_Modify(RFB, "+Select +Focus")
break
}
}
;LV_ModifyCol(1, "Sort")
;LV_Modify(LV_GetCount(), "Vis") ;scroll to last position lastline
LV_Modify(RFB, "Vis") ; scrollto row visible aera
return
;--------------------
2GuiClose:
exitapp
;--------------------
LW2:
Gui,2:Submit,nohide
Gui,2:Default
Gui,2:Listview,A1
if A_GuiEvent = Normal
LV_GetText(C1,A_EventInfo,1)
if A_GuiEvent=doubleclick
{
LV_GetText(C1,A_eventinfo,1)
LV_GetText(C2,A_eventinfo,2)
IniWrite,%C1% , %rssini% ,LASTSELECTEDXX , KEY4
run,%C2%
}
return
;==========================================================
|
Last edited by garry on Wed Feb 10, 2010 6:19 am; edited 2 times in total |
|
| Back to top |
|
 |
arsan
Joined: 02 Jan 2010 Posts: 105
|
Posted: Tue Feb 09, 2010 8:29 pm Post subject: Re: Selecting a LISTVIEW item |
|
|
| Bartimus wrote: | I'm not figuring out how to have AHK select a line in a LISTVIEW automatically. Basically I'm looking for a way for AHK to read from an INI file of a previously selected entry (which is written to on a previous use of the AHK) then automatically highlight/select that same entry.
Can anyone help? |
Just have a look in the doc for help on the command Control:
| Quote: | Control
--------------------------------------------------------------------------------
Makes a variety of changes to a control.
Control, Cmd [, Value, Control, WinTitle, WinText, ExcludeTitle, ExcludeText] |
Specially these parts:
| Quote: | Choose, N: Sets the selection in a ListBox or ComboBox to be the Nth entry. N should be 1 for the first entry, 2 for the second, etc. To select or deselect all items in a multi-select listbox, follow these examples:
PostMessage, 0x185, 1, -1, ListBox1, WinTitle ; Select all listbox items. 0x185 is LB_SETSEL.
ChooseString, String: Sets the selection (choice) in a ListBox or ComboBox to be the first entry whose leading part matches String. The search is not case sensitive. For example, if a ListBox/ComboBox contains the item "UNIX Text", specifying the word unix (lowercase) would be enough to select it.
|
EDIT: Oops! I confused ListView with ListBox. Sorry. Gotta get some sleep.
Last edited by arsan on Tue Feb 09, 2010 10:32 pm; edited 1 time in total |
|
| Back to top |
|
 |
Bartimus
Joined: 10 Nov 2005 Posts: 164 Location: Texas
|
Posted: Tue Feb 09, 2010 8:44 pm Post subject: |
|
|
Garry, thanks... got it to work.
One thing. Even though it will select the last item used, if that item falls off the bottom of the visible area of the listview, you can't see it being selected. Anyway to force the listview to scroll down to that item? |
|
| Back to top |
|
 |
garry
Joined: 19 Apr 2005 Posts: 2214 Location: switzerland
|
Posted: Tue Feb 09, 2010 9:56 pm Post subject: |
|
|
don't know
just a command scroll to last line
| Code: | .....
LV_ModifyCol(1, "Sort")
LV_Modify(LV_GetCount(), "vis") ;scroll to last position lastline
return
|
|
|
| Back to top |
|
 |
Leef_me
Joined: 08 Apr 2009 Posts: 5336 Location: San Diego, California
|
Posted: Tue Feb 09, 2010 10:05 pm Post subject: |
|
|
| Bartimus wrote: | Garry, thanks... got it to work.
One thing. Even though it will select the last item used, if that item falls off the bottom of the visible area of the listview, you can't see it being selected. Anyway to force the listview to scroll down to that item? |
http://www.autohotkey.com/docs/commands/ListView.htm#bifRow
Row Functions
Vis [1.0.44+]: Ensures that the specified row is completely visible by scrolling the ListView, if necessary. This has an effect only for LV_Modify(); for example: LV_Modify(RowNumber, "Vis") |
|
| Back to top |
|
 |
Bartimus
Joined: 10 Nov 2005 Posts: 164 Location: Texas
|
Posted: Tue Feb 09, 2010 10:07 pm Post subject: |
|
|
No... didn't work. List positioned to the end even the the correct line item was selected.
So far the only thing I have is a SEND, {DOWN}{UP} after the item is selected, which works |
|
| Back to top |
|
 |
Bartimus
Joined: 10 Nov 2005 Posts: 164 Location: Texas
|
Posted: Tue Feb 09, 2010 10:10 pm Post subject: |
|
|
actually, this worked: | Code: | searchedfile=%R3X%
LV_Modify(RFB, "-Select -Focus")
RFB:=0
loop, % LV_GetCount()
{
RFB:=(RFB+1)
LV_GetText(CKL,RFB,1)
ifinstring,CKL,%searchedfile%
{
LV_Modify(RFB, "+Select +Focus")
break
}
}
LV_ModifyCol(1, "Sort")
LV_Modify(RFB, "Vis") ;Use last RFB increment
return |
|
|
| Back to top |
|
 |
garry
Joined: 19 Apr 2005 Posts: 2214 Location: switzerland
|
Posted: Tue Feb 09, 2010 10:19 pm Post subject: |
|
|
thank you Leef_me and Bartimus, had a problem with sort, so I moved the sort command
| Code: | ....
;Loop, %DrvLtr%:\M_VIDEO\*.*,0,1
Loop, %DrvLtr%:\portable\*.*
LV_Add("", A_LoopFileName,A_LoopFileFullPath)
LV_ModifyCol(1, "Sort")
searchedfile=%R3X%
LV_Modify(RFB, "-Select -Focus")
RFB:=0
loop, % LV_GetCount()
{
RFB:=(RFB+1)
LV_GetText(CKL,RFB,1)
ifinstring,CKL,%searchedfile%
{
LV_Modify(RFB, "+Select +Focus")
;LV_Modify(RFB, "Vis")
break
}
}
;LV_ModifyCol(1, "Sort")
;LV_Modify(LV_GetCount(), "vis") ;scroll to last position lastline
LV_Modify(RFB, "Vis")
return
|
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|