AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

DropDownList controlling a ListView

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
JamesVan



Joined: 01 Oct 2007
Posts: 17

PostPosted: Tue Dec 18, 2007 5:49 pm    Post subject: DropDownList controlling a ListView Reply with quote

Hi,

I'm trying to create a GUI in which selections in a dropdownlist would change what's displayed in a ListView. The goal is to find files matching a certain filter, but look in different folders as per the selection in the DropDownList.

Here's what I have so far. (The GUI just closes when I pick a different item in the DropDownList.)

Code:

DSCPLN = A
CENTRALPATH = W:\%DSCPLN%\BIM
Goto, GetCentrals

GetCentrals:

; Create the ListView with two columns, Name and Size:
Gui, Add, DropDownList, Choose1 vDiscipline gGetFolder, Architecture|Interiors|Structure
Gui, Add, ListView, r20 w700 gMyListView, Name|Size (KB)

; Gather a list of file names from a folder and put them into the ListView:
Loop, %CENTRALPATH%\*CENTRAL.rvt
    LV_Add("", A_LoopFileName, A_LoopFileSizeKB)

LV_ModifyCol()  ; Auto-size each column to fit its contents.
LV_ModifyCol(2, "Integer")  ; For sorting purposes, indicate that column 2 is an

integer.

; Display the window and return. The script will be notified whenever the user double

clicks a row.
Gui, Show
return

MyListView:
if A_GuiEvent = DoubleClick
{
    LV_GetText(RowText, A_EventInfo)  ; Get the text from the row's first field.
    ToolTip You double-clicked row number %A_EventInfo%. Text: "%RowText%"
}
return

GuiClose:  ; Indicate that the script should exit automatically when the window is

closed.


GetFolder:
;MsgBox, Switch to other folder.
If Discipline = Architecture
{
   CENTRALPATH = W:\A\BIM
   GuiControl,,MyListView
   Return
}
If Discipline = Interiors
{
   CENTRALPATH = W:\I\BIM
   GuiControl,,MyListView
   Return
}
If Discipline = Structure
{
   CENTRALPATH = W:\S\BIM
   GuiControl,,MyListView
   Return
}


ExitApp


Any help is greatly appreciated!

Sincerely,
James V
Back to top
View user's profile Send private message
garry



Joined: 19 Apr 2005
Posts: 1030
Location: switzerland

PostPosted: Tue Dec 18, 2007 6:28 pm    Post subject: Reply with quote

( see last script )

Last edited by garry on Wed Dec 19, 2007 12:11 pm; edited 1 time in total
Back to top
View user's profile Send private message
JamesVan



Joined: 01 Oct 2007
Posts: 17

PostPosted: Tue Dec 18, 2007 6:40 pm    Post subject: Reply with quote

Thanks garry. I see you moved "ExitApp" above the labels for the drop down choices which kept the window from closing; however, the list of files is not updating based on the choices in the DropDownList.
Back to top
View user's profile Send private message
garry



Joined: 19 Apr 2005
Posts: 1030
Location: switzerland

PostPosted: Tue Dec 18, 2007 6:50 pm    Post subject: Reply with quote

( see last script )

Last edited by garry on Wed Dec 19, 2007 12:11 pm; edited 1 time in total
Back to top
View user's profile Send private message
JamesVan



Joined: 01 Oct 2007
Posts: 17

PostPosted: Tue Dec 18, 2007 7:36 pm    Post subject: Reply with quote

Thanks again, garry.

I couldn't get the GoSub function to work in my code, but since you replied I looked at the ListView example in the Help file. This helped me get almost finished.

The last part I can't figure out is how to get the text from the selected rows (yes, it should allow for multiple selections) into a variable for further loop processing.
Code:
#SingleInstance force
#NoTrayIcon

DSCPLN = A
CENTRALPATH = W:\%DSCPLN%\BIM
Gui, Add, DropDownList, Choose1 vDiscipline gGetFolder, Architecture|Interiors|Structure
Gui, Add, Text,, Select which central files to copy locally:
Gui, Add, ListView, r10 w400 Checked vMyListView, Name|Size (KB)

Loop, %CENTRALPATH%\*CENTRAL.rvt
    LV_Add("", A_LoopFileName, A_LoopFileSizeKB)

LV_ModifyCol()  ; Auto-size each column to fit its contents.
LV_ModifyCol(2, "Integer")  ; For sorting purposes, indicate that column 2 is an
LV_ModifyCol(2, 60) ; Make the Size column at little wider to reveal its header.

Gui, Add, Button, Default, Start Copy
Gui, Add, Button, x+20, Cancel
Gui, Show
UserSelect = LV_GetCount("Selected")
LV_GetText(UserFiles, LV_GetCount("Selected"))
return

ButtonStartCopy:

msgbox, Row: %UserSelect%`nFile selected: %UserFiles%
ButtonCancel:
GuiClose:  ; Indicate that the script should exit automatically when the window is
exitapp

GetFolder:
Gui,submit,nohide
GuiControl, -Redraw, MyListView
If Discipline = Architecture
{
   ;msgbox,WA
   CENTRALPATH = W:\A\BIM
}
If Discipline = Interiors
{
   ;msgbox,WI
   CENTRALPATH = W:\I\BIM
}
If Discipline = Structure
{
   ;msgbox,WS
   CENTRALPATH = W:\S\BIM
}
LV_Delete() ; Clear the list view first
GuiControl, -Redraw, MyListView
Loop, %CENTRALPATH%\*CENTRAL.rvt
    LV_Add("", A_LoopFileName, A_LoopFileSizeKB)

LV_ModifyCol()  ; Auto-size each column to fit its contents.
LV_ModifyCol(2, "Integer")  ; For sorting purposes, indicate that column 2 is an
LV_ModifyCol(2, 60) ; Make the Size column at little wider to reveal its header.
GuiControl, +Redraw, MyListView
Return
Back to top
View user's profile Send private message
garry



Joined: 19 Apr 2005
Posts: 1030
Location: switzerland

PostPosted: Tue Dec 18, 2007 7:56 pm    Post subject: Reply with quote

( see last script )

Last edited by garry on Wed Dec 19, 2007 12:10 pm; edited 1 time in total
Back to top
View user's profile Send private message
JamesVan



Joined: 01 Oct 2007
Posts: 17

PostPosted: Tue Dec 18, 2007 9:09 pm    Post subject: Reply with quote

Alright, that works. Now I'm assuming that I'll have to use some kind of loop to process multiple selections, correct?
Back to top
View user's profile Send private message
garry



Joined: 19 Apr 2005
Posts: 1030
Location: switzerland

PostPosted: Tue Dec 18, 2007 11:45 pm    Post subject: Reply with quote

hello JamesVan,
this copy multiple marked lines
but , I think you want copy checked lines, I'll come back later...

( see last script )


Last edited by garry on Wed Dec 19, 2007 12:10 pm; edited 1 time in total
Back to top
View user's profile Send private message
garry



Joined: 19 Apr 2005
Posts: 1030
Location: switzerland

PostPosted: Wed Dec 19, 2007 12:09 pm    Post subject: Reply with quote

( removed scripts above )
here completed
Code:
/*
    this script copies selected/marked  from c:\testB   to  c:\testC
    copy with button or rightclick
*/

#NoEnv
#SingleInstance force
SetBatchLines,-1
setworkingdir, %a_scriptdir%

DSCPLN = A
CENTRALPATH = c:\testB                      ;for test
Gui, Add, DropDownList, Choose1 vDiscipline gGetFolder, Architecture|Interiors|Structure
Gui, Add, Text,, Select which central files to copy locally:

Gui, Add, ListView, r10 w400 Checked altsubmit vMLV1 gMLV2, Name|Size

Loop, %CENTRALPATH%\*.*
    LV_Add("", A_LoopFileName, A_LoopFileSize)

LV_ModifyCol()                  ; Auto-size each column to fit its contents.
LV_ModifyCol(2, "Integer")      ; For sorting purposes, indicate that column 2 is an
LV_ModifyCol(2, 60)             ; Make the Size column at little wider to reveal its header.

Gui, Add, Button, Default, Start Copy
Gui, Add, Button, x+20, Cancel
Gui, Show
return
;------------------------------------------------

;-----------------------------------------------------------
MLV2:
Gui,submit,nohide
Gui,ListView,MLV1
  RN:=LV_GetNext("C")
  RF:=LV_GetNext("F")
  GC:=LV_GetCount()

if A_GuiEvent = Normal
   {
   if (RF="" OR RF=0)
      return
   LV_GetText(C1,A_EventInfo,1)
   LV_GetText(C2,A_EventInfo,2)
   }

;---- copy all marked -----------
if A_GuiEvent = Rightclick
   {
   C1x=
   RF = 0
   Loop
     {
     RF:=LV_GetNext(RF)
     if RF=0
        break
     LV_GetText(C1_Temp, RF, 1)
     C1x = %C1x%`n%C1_Temp%
     }

  if C1x !=
     {
     MsgBox, 4, ,Want you copy %C1x% to c:\testc ?
     IfMsgBox,No
         Return
     Else
          {
         StringSplit,D,C1x,`n
         loop,%D0%
             {
              DY=%A_INDEX%                            ;    1 2 3
              if DY=1
                 continue
              DX:=D%A_INDEX%                          ;string
              msgbox,%centralpath%\%DX%               ;msgbox for control
              Filecopy,%centralpath%\%DX%,c:\testc    ;copy to c:\testc
              }
          }
      }
run,c:\testc
return
  }
return
;--------------------------------------------------------------------



;------------- copy checked ----------------------------------------
ButtonStartCopy:
gui,submit,nohide
RNM =0
Loop
    {
    RNM := LV_GetNext(RNM,"checked")
    if not RNM
        break
    LV_GetText(C1,RNM,1)
    msgbox,%centralpath%\%C1%                ;msgbox for control
    Filecopy,%centralpath%\%C1%,c:\testc    ;copy to c:\testc
    }
run,c:\testc                                  ;opens folder where copied
return
;-------------------------------------------------------------



;-----------------------------------
GetFolder:
Gui,submit,nohide
GuiControl, -Redraw, MyListView
If Discipline = Architecture
   {
   msgbox,W:\A\BIM
   CENTRALPATH = W:\A\BIM
   }
If Discipline = Interiors
   {
   msgbox,W:\I\BIM
   CENTRALPATH = W:\I\BIM
   }
If Discipline = Structure
   {
   msgbox,C:\testB
   CENTRALPATH =C:\testb
   }

FILLLIST:
LV_Delete()                       ; Clear the list view first
GuiControl, -Redraw, MLV1
Loop, %CENTRALPATH%\*.*
    LV_Add("", A_LoopFileName, A_LoopFileSize)

LV_ModifyCol()                 ; Auto-size each column to fit its contents.
LV_ModifyCol(2, "Integer")     ; For sorting purposes, indicate that column 2 is an
LV_ModifyCol(2, 60)            ; Make the Size column at little wider to reveal its header.
GuiControl, +Redraw, MLV1
Return
;---------------------------

ButtonCancel:
GuiClose:
exitapp
;----------------------------------------------------------------------------

Back to top
View user's profile Send private message
JamesVan



Joined: 01 Oct 2007
Posts: 17

PostPosted: Wed Dec 19, 2007 2:55 pm    Post subject: Reply with quote

PERFECT!! Thank you so much for your help, garry!

- James V
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group