AutoHotkey Community

It is currently May 27th, 2012, 2:28 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: February 8th, 2010, 8:28 pm 
Offline

Joined: November 10th, 2005, 11:26 pm
Posts: 169
Location: Texas
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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 9th, 2010, 12:50 am 
Offline

Joined: April 8th, 2009, 7:49 pm
Posts: 6071
Location: San Diego, California
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 ... 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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 9th, 2010, 7:19 am 
Offline

Joined: November 10th, 2005, 11:26 pm
Posts: 169
Location: Texas
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 9th, 2010, 11:19 am 
Offline

Joined: April 19th, 2005, 10:26 am
Posts: 2249
Location: switzerland
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 February 10th, 2010, 7:17 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 9th, 2010, 6:26 pm 
Offline

Joined: November 10th, 2005, 11:26 pm
Posts: 169
Location: Texas
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 9th, 2010, 8:39 pm 
Offline

Joined: April 19th, 2005, 10:26 am
Posts: 2249
Location: switzerland
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 February 10th, 2010, 7:19 am, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
PostPosted: February 9th, 2010, 9:29 pm 
Offline

Joined: January 2nd, 2010, 6:13 pm
Posts: 105
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 February 9th, 2010, 11:32 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 9th, 2010, 9:44 pm 
Offline

Joined: November 10th, 2005, 11:26 pm
Posts: 169
Location: Texas
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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 9th, 2010, 10:56 pm 
Offline

Joined: April 19th, 2005, 10:26 am
Posts: 2249
Location: switzerland
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 9th, 2010, 11:05 pm 
Offline

Joined: April 8th, 2009, 7:49 pm
Posts: 6071
Location: San Diego, California
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 ... 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")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 9th, 2010, 11:07 pm 
Offline

Joined: November 10th, 2005, 11:26 pm
Posts: 169
Location: Texas
:( 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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 9th, 2010, 11:10 pm 
Offline

Joined: November 10th, 2005, 11:26 pm
Posts: 169
Location: Texas
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 9th, 2010, 11:19 pm 
Offline

Joined: April 19th, 2005, 10:26 am
Posts: 2249
Location: switzerland
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


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Alpha Bravo, LazyMan, rbrtryn and 23 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group