Filer listview records in gui Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
taylorkt
Posts: 1
Joined: 22 May 2020, 15:38

Filer listview records in gui

22 May 2020, 16:37

Hello:

First time poster. I found some great code for a gui with listview that I copied from a user on this forum (kudos to them all the other great AKH Forum posters), complete with buttons to add, delete, edit and move the records in the listview. I have since modified the code to fit some of my needs (i.e., I added some extra columns and I added text fields to the user form).

In short, I am trying to figure out how to filter the listview records based on the user clicking the text "Financial Assistance" on the user form. I would like to be able to click on text "Financial Assistance" and then automatically have the listview update to only show records from the ini/text file that start with "FAP" in each row.

My txt data file (CAF Communication Templates.txt) is as follows:

CASP;Payment;Stop Payment;Request stop payment;English1;Spanish1;Russian1;Portuguese1
FAP;Payment;Stop Payment;Request stop payment;English;Spanish;Russian;Portuguese
FAP;Application;Income;Income document protected;English;Spanish;Russian;Portuguese
FAP;Payment;Void Check;Request stop payment;English1;Spanish1;Russian1;Portuguese1


The code below is lengthy, so the code I am looking for help with is under "FAPClicked:" (line 197). Thank you in advance for your assistance!

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
;#NoTrayIcon
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance force

F6::

;--------------------------------------------------------------------------------------------------------------------------------------------
DefaultButtonSize := "w75 h23"                ;-The standard button size used in system dialogues (e.g. Mouse Settings). Changing this might mess with the placement of controls in the window.

;Menu, Tray, Icon, imageres.dll, 90            ;-Set the titlebar icon.
MainWindowTitle := "CAF Communication Templates"    ;-Set the window title.

d= `;                                                   ;-Delimiter


F1=%a_scriptdir%\%MainWindowTitle%.txt
e4x=
(Ltrim Join`r`n
Launch Calculator%d%Ctrl+Shift+Windows+C
Launch Paint%d%Ctrl+Shift+Windows+P
Launch Notepad%d%Ctrl+Shift+Windows+N
111111111%d%22222222222222
)
ifnotexist,%f1%
  fileappend,%e4x%,%f1%


;--------------------------------------------------------------------------------------------------------------------------------------------
;For these variables, append the same name to the variables with the same number, but in the variable %Name#% insert an ampersand (&) symbol before the letter that is to be used with ALT shortcuts.
;Also specify a default width for each column. If none is specified

Column1Name = Program
1Name = Program
Column1Width = 60

Column2Name = Process
2Name = Process
Column2Width = 80

Column3Name = Type
3Name = Type
Column3Width = 80

Column4Name = Description
4Name = Description
Column4Width = 200

Column5Name = English
5Name = English
Column5Width = 70

Column6Name = Spanish
6Name = Spanish
Column6Width = 70

Column7Name = Russian
7Name = Russian
Column7Width = 70

Column8Name = Portuguese
8Name = Portguese
Column8Width = 70

;Column9Name = 
;9Name =
;Column9Width = 0


;-----------------------------------------------------------------------------------------------------
;CREATE GUI:
;-----------------------------------------------------------------------------------------------------

;TO HIDE AHK ICON IN GUI UPPER LEFT CORNER
Gui +LastFound
DllCall("uxtheme\SetWindowThemeAttribute", "ptr", WinExist()
    , "int", 1, "int64*", 6 | 6<<32, "uint", 8)

Gui, Add, Button, x120 y10 %DefaultButtonSize% vButtonAddRow gButtonAddRow, Add Row
Gui, Add, Button, xp+81 yp %DefaultButtonSize% vButtonEditRow gButtonEditRow, Edit Row
Gui, Add, Button, xp+81 yp %DefaultButtonSize% vButtonDeleteRow gButtonDeleteRow, Delete Row
ButtonDeleteRow_TT := "Delete the selected row (Delete key).`nShift+Delete: no prompt."        ;ToolTip for the Delete button.
Gui, Add, Button, xp+81 yp %DefaultButtonSize% vButtonMoveUp gButtonMoveUp, Move &Up
ButtonMoveUp_TT := "Move the selected rows up one row (PageUp)"                    ;ToolTip for the Move Up button.
Gui, Add, Button, xp+81 yp %DefaultButtonSize% vButtonMoveDown gButtonMoveDown, &Move Down
ButtonMoveDown_TT := "Move the selected rows down one row (PageDown)"                ;ToolTip for the Move Down button.
;Gui, Add, ListView, x100 y40 w500 h200 vMainListView gMainListView Grid -Multi +SortHdr +LV0x4000 +AltSubmit, %Column1Name%|%Column2Name%|%Column3Name%|%Column4Name%|%Column5Name%|%Column6Name%|%Column7Name%|%Column8Name% ;LV0x4000 unfolds partially hidden items in the listview in the form of a tooltip, -Multi only allows one row to be focused at a time, and NoSortHdr disables sorting the listview when a column header is clicked.
Gui, Add, ListView, x120 y40 w500 h200 vMainListView gMainListView Grid -Multi +SortHdr +AltSubmit, %Column1Name%|%Column2Name%|%Column3Name%|%Column4Name%|%Column5Name%|%Column6Name%|%Column7Name%|%Column8Name% ;LV0x4000 unfolds partially hidden items in the listview in the form of a tooltip, -Multi only allows one row to be focused at a time, and NoSortHdr disables sorting the listview when a column header is clicked.


;SIDEBAR MENU
Gui, Font, Bold
Gui, Add, Text, x10 y50, Program
Gui, Font, Normal
Gui, Add, Text, x10 y75 vFAP gFAPClicked, Financial Assistance
Gui, Add, Text, x10 y100, Scholarship

Gui, Font, Bold
Gui, Add, Text, x10 y125, Process
Gui, Font, Normal
Gui, Add, Text, x10 y150, Application Process	
Gui, Add, Text, x10 y175, Consultation Process
Gui, Add, Text, x10 y200, Decision Process
Gui, Add, Text, x10 y225, Payment Process
Gui, Add, Text, x10 y250, Receipt Process
Gui, Add, Text, x10 y275, Closure Process

;Gui, Add, Text, x10 y65 w90 0x10  ;Horizontal Line > Etched Gray

gosub,filllist

    LV_ModifyCol()            ;Attempt to automatically set a column width for those columns where no default is specified.
    LV_ModifyCol(1, 60)    ;Set the default width for these columns.
    LV_ModifyCol(2, 80)
    LV_ModifyCol(3, 80)
    LV_ModifyCol(4, 200)
    LV_ModifyCol(5, 70)
    LV_ModifyCol(6, 70)
    LV_ModifyCol(7, 70)
    LV_ModifyCol(8, 70)
    LV_ModifyCol(9, "AutoHdr")


  ;LV_ModifyCol(1, "Sort")
  LV_Modify(LV_GetCount(), "Vis")     ;scrolls down



;If no name exists for a column, delete the column:
;if Column3Name := ""
;    LV_DeleteCol(3)
;if Column4Name := ""
;    LV_DeleteCol(4)
;if Column4Name := ""
;    LV_DeleteCol(4)
;if Column5Name := ""
;    LV_DeleteCol(5)
;if Column6Name := ""
;    LV_DeleteCol(6)
;if Column7Name := ""
;    LV_DeleteCol(7)
;if Column8Name := ""
;    LV_DeleteCol(8)


;Add the buttons along the bottom:
Gui, Add, Button, x212 y421  %DefaultButtonSize% vButtonOK gButtonOK Default, &OK
Gui, Add, Button, xp+81 yp %DefaultButtonSize% vButtonCancel gButtonCancel, &Cancel
Gui, Add, Button, xp+81 yp %DefaultButtonSize% vButtonApply gButtonApply, &Apply

;Show the GUI and set other options:
Gui, +Resize -MaximizeBox +MinSize411x132
Gui, Show, w1000 h500 , %MainWindowTitle%
OnMessage(0x200, "WM_MOUSEMOVE")        ;For the tooltips.
;Gui, Destroy

return


filllist:
Gui,1:default
Gui,1:Submit,nohide
Gui,1:ListView,MainListView
LV_Delete()
loop,read,%f1%
  {
  b1=
  b2=
  b3=
  b4=
  b5=
  b6=
  b7=
  b8=
  stringsplit,b,A_LoopReadLine,%d%,
  LV_Add("",b1,b2,b3,b4,b5,b6,b7,b8)
  }
Return


PrintLv:

ifexist,%f1%
   filedelete,%f1%
ControlGet,AA,List,,SysListView321,%MainWindowTitle%   ;<< the correct name of listview
stringreplace,A,AA,`t,%d%,all                          ;<< replaces TAB with Delimiter `;
stringreplace,A,A,`n,`r`n,all
fileappend,%A%,%F1%
return

;---------------------------------------------------------------------------------------------------------------------
;FAP CLICKED
;---------------------------------------------------------------------------------------------------------------------

FAPClicked:
	
	FAP := FAP

	;Clear Listview
	Gui,1:default
	Gui,1:Submit,nohide
	Gui,1:ListView,MainListView
	LV_Delete()

	;Repopulate Listview
	Gui,1:ListView,MainListView

loop,read,%f1%
 
	{
    Loop, parse, A_LoopReadLine, %A_Tab%
    {
        
	If %A_Index% = %FAP%
	LV_Add("",b1,b2,b3,b4,b5,b6,b7,b8)
	
    }
}
	Return

;---------------------------------------------------------------------------------------------------------------------
; ADD ROW BUTTON
;---------------------------------------------------------------------------------------------------------------------

    ButtonAddRow:
    Gui, AddRow:+Owner1                          		;Make the main window the owner of this window.
    Gui +Disabled                                		;Disable the main window.

;PROGRAM
    Gui, AddRow:Add, Text, x6 y8, %1Name%:       		;Adds the text control for the first column (see variable at very top for name).
    gosub, GetFocusedRowNumber                   		;See label at bottom.    
    Gui, AddRow:Add, Edit, x70 y6 w270 vAddRowEditCol1,         ;Creates the first blank Edit control.

;PROCESS
    Gui, AddRow:Add, Text, x6 y40, %2Name%:                	;Adds the text control for the second column (see variable at very top for name).
    Gui, AddRow:Add, Edit, x70 y38 w270 vAddRowEditCol2,    	;Creates the second blank Edit control.

;TYPE
    Gui, AddRow:Add, Text, x6 y72, %3Name%:                	;Adds the text control for the third column (see variable at very top for name).
    Gui, AddRow:Add, Edit, x70 y70 w270 vAddRowEditCol3,    	;Creates the third blank Edit control.

;DESCRIPTION
    Gui, AddRow:Add, Text, x6 y104, %4Name%:                	;Adds the text control for the fourth column (see variable at very top for name).
    Gui, AddRow:Add, Edit, x70 y102 w270 vAddRowEditCol4,    	;Creates the fourth blank Edit control.

;ENGLISH
    Gui, AddRow:Add, Text, x6 y136, %5Name%:               	;Adds the text control for the fifth column (see variable at very top for name).
    Gui, AddRow:Add, Edit, x70 y134 w270 h80 vAddRowEditCol5,    	;Creates the fifth blank Edit control.

;SPANISH
    Gui, AddRow:Add, Text, x6 y228, %6Name%:               	;Adds the text control for the sixth column (see variable at very top for name).
    Gui, AddRow:Add, Edit, x70 y226 w270 h80 vAddRowEditCol6,  ;Creates the sixth blank Edit control.

;RUSSIAN
    Gui, AddRow:Add, Text, x6 y320, %7Name%:               	;Adds the text control for the seventh column (see variable at very top for name).
    Gui, AddRow:Add, Edit, x70 y318 w270 h80 vAddRowEditCol7,  ;Creates the seventh blank Edit control.

;PORTUGUESE
    Gui, AddRow:Add, Text, x6 y412, %8Name%:               	;Adds the text control for the eight column (see variable at very top for name).
    Gui, AddRow:Add, Edit, x70 y410 w270 h80 vAddRowEditCol8,  ;Creates the eigth blank Edit control.

;OK BUTTON
    Gui, AddRow:Add, Button, x185 y500 %DefaultButtonSize% vAddRowButtonOK gAddRowButtonOK    Default, &OK    	;Adds the OK button (see label below).

;CANCEL BUTTON
    Gui, AddRow:Add, Button, x265 y500 %DefaultButtonSize% vAddRowButtonCancel gAddRowButtonCancel, &Cancel    		;Adds the Cancel button (see label below).

;GUI PARAMETERS
    Gui, AddRow: -MaximizeBox -MinimizeBox                    	;Removes the maximise and minimise buttons from the titlebar.
    Gui, AddRow:Show, w355 h535, Add Row                    	;Shows the AddRow dialogue and sets the window size and title.
    
    return

;---------------------------------------------------------------------------------------------------------------------
;ADD ROW OK BUTTON
;---------------------------------------------------------------------------------------------------------------------
    AddRowButtonOK:
    Gui, AddRow:Submit, NoHide        	;Submit the contents of the controls into their respective variables.
    gosub, CloseChildGui        	;See label at bottom.
    RowNumber := RowNumber + 1        	;Add 1 to %RowNumber% to insert it below the focused row instead of above it.
    LV_Insert(RowNumber, "", AddRowEditCol1, AddRowEditCol2, AddRowEditCol3, AddRowEditCol4, AddRowEditCol5, AddRowEditCol6, AddRowEditCol7, AddRowEditCol8)    ;Insert the new row with column fields from the variables attached to the Edit boxes in the "AddRow..." dialogue.
    return

;---------------------------------------------------------------------------------------------------------------------
;EDIT ROW BUTTON
;---------------------------------------------------------------------------------------------------------------------
    ;Create the "Edit Row" dialogue when the EditRow button is clicked.
    ;(basically the same as the "AddRow" dialogue except here the current contents of the row that is being edited are shown in the Edit controls instead of being blank):
    ButtonEditRow:
    Gui, 2:Submit
    Gui, 1:Default
    MouseGetPos, MouseX, MouseY             ;Gets the current location of the mouse
    MouseX := MouseX + 50
    Gui, EditRow:+Owner1
    Gui +Disabled
    Gui, EditRow:Add, Text, x6 y9, %1Name%:
    gosub, GetFocusedRowNumber
   
    LV_GetText(Col1Text, RowNumber, 1)        ;Gets the text in row number %RowNumber%, column 1 and saves it in %Col1Text%.
    LV_GetText(Col2Text, RowNumber, 2)        ;Gets the text in row number %RowNumber%, column 2 and saves it in %Col2Text%.
    LV_GetText(Col3Text, RowNumber, 3)        ;Gets the text in row number %RowNumber%, column 3 and saves it in %Col3Text%.
    LV_GetText(Col4Text, RowNumber, 4)        ;Gets the text in row number %RowNumber%, column 4 and saves it in %Col3Text%.
    LV_GetText(Col5Text, RowNumber, 5)        ;Gets the text in row number %RowNumber%, column 6 and saves it in %Col3Text%.
    LV_GetText(Col6Text, RowNumber, 6)        ;Gets the text in row number %RowNumber%, column 6 and saves it in %Col3Text%.
    LV_GetText(Col7Text, RowNumber, 7)        ;Gets the text in row number %RowNumber%, column 7 and saves it in %Col3Text%.
    LV_GetText(Col8Text, RowNumber, 8)        ;Gets the text in row number %RowNumber%, column 8 and saves it in %Col3Text%.
 
;PROGRAM   
    Gui, EditRow:Add, Text, x6 y8, %1Name%:
     gosub, GetFocusedRowNumber
    Gui, EditRow:Add, Edit, x70 y6 w270 vEditRowEditCol1, %Col1Text%    ;Creates the first Edit control and inserts the text from %Col1Text% into it (this works fine).

;PROCESS
    Gui, EditRow:Add, Text, x6 y40, %2Name%:
    Gui, EditRow:Add, Edit, x70 y38 w270 vEditRowEditCol2, %Col2Text%    ;Creates the second Edit control and inserts the text from %Col2Text% into it (this works fine).

;TYPE
    Gui, EditRow:Add, Text, x6 y72, %3Name%:
    Gui, EditRow:Add, Edit, x70 y70 w270 vEditRowEditCol3, %Col3Text%    ;Creates the third Edit control and inserts the text from %Col3Text% into it (this works fine).

;DESCRIPTION
    Gui, EditRow:Add, Text, x6 y104, %4Name%:
    Gui, EditRow:Add, Edit, x70 y102 w270 vEditRowEditCol4, %Col4Text%    ;Creates the fourth Edit control and inserts the text from %Col4Text% into it (this works fine).

;ENGLISH
    Gui, EditRow:Add, Text, x6 y136, %5Name%:
    Gui, EditRow:Add, Edit, x70 y134 w270 h80 vEditRowEditCol5, %Col5Text%    ;Creates the fifth Edit control and inserts the text from %Col5Text% into it (this works fine).

;SPANISH
    Gui, EditRow:Add, Text, x6 y228, %6Name%:
    Gui, EditRow:Add, Edit, x70 y226 w270 h80 vEditRowEditCol6, %Col6Text%    ;Creates the sixth Edit control and inserts the text from %Col6Text% into it (this works fine).

;RUSSIAN
    Gui, EditRow:Add, Text, x6 y320, %7Name%:
    Gui, EditRow:Add, Edit, x70 y318 w270 h80 vEditRowEditCol7, %Col7Text%    ;Creates the seventh Edit control and inserts the text from %Col7Text% into it (this works fine).

;PORTUGUESE
    Gui, EditRow:Add, Text, x6 y412, %8Name%:
    Gui, EditRow:Add, Edit, x70 y410 w270 h80 vEditRowEditCol8, %Col8Text%    ;Creates the eigth Edit control and inserts the text from %Col8Text% into it (this works fine).

;OK BUTTON
    Gui, EditRow:Add, Button, x185 y500 %DefaultButtonSize% vEditRowButtonOK gEditRowButtonOK Default, &OK

;CANCEL BUTTON
    Gui, EditRow:Add, Button, x265 y500 %DefaultButtonSize% vEditRowButtonCancel gEditRowButtonCancel, &Cancel

;GUI PARAMETERS
    Gui, EditRow: -MaximizeBox -MinimizeBox
    Gui, EditRow:Show,  w355 h535, Edit Row
    return

;---------------------------------------------------------------------------------------------------------------------
;EDIT ROW OK BUTTON
;---------------------------------------------------------------------------------------------------------------------
    EditRowButtonOK:        ;Same as the AddRowButtonOK label above except for the LV_Modify instead of LV_Insert.
    Gui, EditRow:Submit, NoHide
    gosub, CloseChildGui
    LV_Modify(RowNumber, "", EditRowEditCol1, EditRowEditCol2,EditRowEditCol3, EditRowEditCol4, EditRowEditCol5, EditRowEditCol6, EditRowEditCol7, EditRowEditCol8)
    return

;---------------------------------------------------------------------------------------------------------------------
;DELETE ROW BUTTON
;---------------------------------------------------------------------------------------------------------------------
    ;Create the Delete confirmation dialogue when the Delete button is pressed:
    ButtonDeleteRow:
    #IfWinActive, CAF Communication Templates
    Delete::
    #IfWinActive
    Gui, 1:Default
    gosub, GetFocusedRowNumber
    if RowNumber = 0    ;If there is no row selected in the listview, do nothing.
    return
    ;Menu, Tray, Icon, imageres.dll, 85    ;shell32.dll, 238 for Exclamation icon.
    Gui, DeleteRow:+Owner1            ;Make the main window the owner of this window.
    Gui +Disabled                ;Disable the main window.
    Gui, DeleteRow:Add, Picture, w-1 h32 x11 y11 Icon272, %A_WinDir%\System32\shell32.dll        ;Add the "Delete File" icon.
    Gui, DeleteRow:Add, Text, xp+48 yp, Are you sure you want to permanently delete this row?    ;Add "Are you sure...?" text.
    LV_GetText(Col1Text, RowNumber, 1)    ;Get the text in row number %RowNumber%, column 1 and save it in %Col1Text%.
   ; LV_GetText(Col2Text, RowNumber, 2)    ;Get the text in row number %RowNumber%, column 2 and save it in %Col2Text%.
   ; Gui, DeleteRow:Add, Text, xp+30 yp+18, %Col1Text%
   ; Gui, DeleteRow:Add, Text, xp yp+18, %Col2Text%
    ;~ Gui, DeleteRow:Default            ;Temporarily make this dialogue window the primary one in order to create a listview.
    ;~ Gui, DeleteRow:Add, ListView, xp y38 w283 r1 vDeleteRowListView +Grid -Hdr +LV0x4000, ;%Column1Name%|%Column2Name%    ;-Hdr removes column titles; +LV0x4000 unfolds partially hidden columns.
    ;~ LV_Add("", Col1Text, Col2Text)          ;Add the row that is going to be deleted.
    ;~ LV_ModifyCol(1, 163)
    ;~ LV_ModifyCol(2, 120)
    Gui, DeleteRow:Add, Button, x187 y72 %DefaultButtonSize% vDeleteRowButtonYes gDeleteRowButtonYes Default, &Yes    ;Add Yes button.
    Gui, DeleteRow:Add, Button, xp+81 yp %DefaultButtonSize% vDeleteRowButtonNo gDeleteRowButtonNo, &No        ;Add No button.
    Gui, DeleteRow: -MaximizeBox -MinimizeBox        ;Remove the minimise and maximise buttons in the titlebar.
    Gui, DeleteRow:Show, w350 h102, Delete Row        ;Show the GUI and set the window size.
    return

;---------------------------------------------------------------------------------------------------------------------
;DELETE ROW YES BUTTON
;---------------------------------------------------------------------------------------------------------------------
    DeleteRowButtonYes:
    #IfWinActive, Delete Row
    Delete::
    gosub,CloseChildGui
    LV_Delete(RowNumber)        ;Delete the row specified by %RowNumber% when Yes is pressed.
    #IfWinActive
    return
    ;DeleteRowButtonNo is at the bottom.


    #IfWinActive, CAF Communication Templates
    +Delete::            ;Delete the row specified by %RowNumber% and show no warning when shift is held down and Delete is pressed or clicked.
    #IfWinActive
    LV_Delete(RowNumber)
    return

;---------------------------------------------------------------------------------------------------------------------
;MOVE UP BUTTON
;---------------------------------------------------------------------------------------------------------------------
    ButtonMoveUp:          ;When PageUp is pressed or ButtonMoveUp is clicked, move the selected rows up one.
    PgUp::
    LV_MoveRow()    ;Refer to functions list below.
    return

;---------------------------------------------------------------------------------------------------------------------
;MOVE DOWN BUTTON
;---------------------------------------------------------------------------------------------------------------------
    ButtonMoveDown:                 ;When PageDown is pressed or ButtonMoveDown is clicked, move the selected rows down one.
    PgDn::
    LV_MoveRow(false)       ;Refer to functions list below.
    return

;---------------------------------------------------------------------------------------------------------------------
;OK BUTTON
;---------------------------------------------------------------------------------------------------------------------
    ButtonOK:
    ;Save to *.ini file and close the window.
    gosub,printlv
    ;ExitApp
    ;Gui, Destroy

;---------------------------------------------------------------------------------------------------------------------
;APPLY BUTTON
;---------------------------------------------------------------------------------------------------------------------   
	ButtonApply:
    ;Save to *.ini file but don't close the window.
    gosub,printlv
    return

;---------------------------------------------------------------------------------------------------------------------
;CANCEL BUTTON
;---------------------------------------------------------------------------------------------------------------------
    ;The Escape key and the Cancel and X buttons close the GUI and the script without saving.
    ButtonCancel:
    GuiClose:
    GuiEscape:
    ;ExitApp
	Gui, Destroy

;---------------------------------------------------------------------------------------------------------------------
;DOUBLE-CLICK RECORD IN LISTVIEW
;---------------------------------------------------------------------------------------------------------------------
MainListview:
if A_GuiEvent = DoubleClick     ;Double-clicking a row opens the Edit Row dialogue window.
gosub, ButtonEditRow
return

;---------------------------------------------------------------------------------------------------------------------
;RESIZE GUI IN RESPONSE TO USER GUI SIZE CHANGE
;---------------------------------------------------------------------------------------------------------------------
;Expand/shrink and move controls in response to the user's resizing of the window:
GuiSize:
if A_EventInfo = 1    ;The window has been minimized.  No action needed.
    return
GuiControl, Move, MainListView, % "W" . (A_GuiWidth - 14) . " H" . (A_GuiHeight - 73)    ;Otherwise, the window has been resized or maximized. Resize the control to match.

;Keep the OK/Cancel/Apply buttons at the bottom right corner and redraw them so they don't appear distorted:
GuiControl, Move, ButtonOK, % "x" . (A_GuiWidth -244) . "y" . (A_GuiHeight - 29)
GuiControl, Move, ButtonCancel, % "x" . (A_GuiWidth -163) . "y" . (A_GuiHeight - 29)
GuiControl, Move, ButtonApply, % "x" . (A_GuiWidth -82) . "y" . (A_GuiHeight - 29)
GuiControl, +Redraw, ButtonOK
GuiControl, +Redraw, ButtonCancel
GuiControl, +Redraw, ButtonApply
return


;====================End of Main Script=====================

;==========Labels Referred to in the Main Script===========
GetFocusedRowNumber:
Gui, 1:Default
RowNumber := "0"            ;Resets the %RowNumber% variable to zero.
RowNumber := LV_GetNext(RowNumber, "Focused")    ;Starts searching for the focused row in the listview at row #0 and stores the focused row in the variable %RowNumber%.
return

MakeOwnerDisableMain:
Gui, DeleteRow:+Owner1        ;Make the main window the owner of this window.
Gui +Disabled            ;Disable the main window.

;All of these Close, Cancel, etc. labels/controls simply close the open dialogue window without any further actions:
CloseChildGui:
EditRowButtonCancel:
EditRowGuiClose:
EditRowGuiEscape:
AddRowButtonCancel:
AddRowGuiClose:
AddRowGuiEscape:
DeleteRowButtonNo:
DeleteRowGuiClose:
DeleteRowGuiEscape:
Gui, 1:-Disabled    ;Re-enable the main window.
Gui Destroy        ;Destroy the dialogue window.
;Menu, Tray, Icon, imageres.dll, 90    ;Reset the tray/titlebar icon.
Gui, 1:Default
return
;=======End of Labels Referred to in the Main Script =======


;==============Functions=================

;This function came from http://www.autohotkey.com/board/topic/56396-techdemo-move-rows-in-a-listview/
LV_MoveRow(moveup = true) {
    ; Original by diebagger (Guest) from:
    ; http de.autohotkey.com /forum/viewtopic.php?p=58526#58526  Broken Link for safety
    ; Slightly Modifyed by Obi-Wahn
    If moveup not in 1,0
        Return    ; If direction not up or down (true or false)
    while x := LV_GetNext(x)    ; Get selected lines
        i := A_Index, i%i% := x
    If (!i) || ((i1 < 2) && moveup) || ((i%i% = LV_GetCount()) && !moveup)
        Return    ; Break Function if: nothing selected, (first selected < 2 AND moveup = true) [header bug]
                ; OR (last selected = LV_GetCount() AND moveup = false) [delete bug]
    cc := LV_GetCount("Col"), fr := LV_GetNext(0, "Focused"), d := moveup ? -1 : 1
    ; Count Columns, Query Line Number of next selected, set direction math.
    Loop, %i% {    ; Loop selected lines
        r := moveup ? A_Index : i - A_Index + 1, ro := i%r%, rn := ro + d
        ; Calculate row up or down, ro (current row), rn (target row)
        Loop, %cc% {    ; Loop through header count
            LV_GetText(to, ro, A_Index), LV_GetText(tn, rn, A_Index)
            ; Query Text from Current and Targetrow
            LV_Modify(rn, "Col" A_Index, to), LV_Modify(ro, "Col" A_Index, tn)
            ; Modify Rows (switch text)
        }
        LV_Modify(ro, "-select -focus"), LV_Modify(rn, "select vis")
        If (ro = fr)
            LV_Modify(rn, "Focus")
    }
}


;Tooltips on GUI controls (this function came from the Help file):
WM_MOUSEMOVE()
{
    static CurrControl, PrevControl, _TT  ; _TT is kept blank for use by the ToolTip command below.
    CurrControl := A_GuiControl
    If (CurrControl <> PrevControl and not InStr(CurrControl, " "))
    {
        ToolTip  ; Turn off any previous tooltip.
        SetTimer, DisplayToolTip, 1000
        PrevControl := CurrControl
    }
    return

    DisplayToolTip:
    SetTimer, DisplayToolTip, Off
    ToolTip % %CurrControl%_TT  ; The leading percent sign tell it to use an expression.
    SetTimer, RemoveToolTip, 3000
    return

    RemoveToolTip:
    SetTimer, RemoveToolTip, Off
    ToolTip
    return
}
;==========End of Functions===========
[Mod edit: added code-tags, and line number to go to]
poetbox
Posts: 112
Joined: 18 Apr 2018, 20:47

Re: Filer listview records in gui  Topic is solved

23 May 2020, 01:39

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
;#NoTrayIcon
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance force

F6::

;--------------------------------------------------------------------------------------------------------------------------------------------
DefaultButtonSize := "w75 h23"                ;-The standard button size used in system dialogues (e.g. Mouse Settings). Changing this might mess with the placement of controls in the window.

;Menu, Tray, Icon, imageres.dll, 90            ;-Set the titlebar icon.
MainWindowTitle := "CAF Communication Templates"    ;-Set the window title.

d= `;                                                   ;-Delimiter


F1=%a_scriptdir%\%MainWindowTitle%.txt
e4x=
(Ltrim Join`r`n
Launch Calculator%d%Ctrl+Shift+Windows+C
Launch Paint%d%Ctrl+Shift+Windows+P
Launch Notepad%d%Ctrl+Shift+Windows+N
111111111%d%22222222222222
)
ifnotexist,%f1%
  fileappend,%e4x%,%f1%


;--------------------------------------------------------------------------------------------------------------------------------------------
;For these variables, append the same name to the variables with the same number, but in the variable %Name#% insert an ampersand (&) symbol before the letter that is to be used with ALT shortcuts.
;Also specify a default width for each column. If none is specified

Column1Name = Program
1Name = Program
Column1Width = 60

Column2Name = Process
2Name = Process
Column2Width = 80

Column3Name = Type
3Name = Type
Column3Width = 80

Column4Name = Description
4Name = Description
Column4Width = 200

Column5Name = English
5Name = English
Column5Width = 70

Column6Name = Spanish
6Name = Spanish
Column6Width = 70

Column7Name = Russian
7Name = Russian
Column7Width = 70

Column8Name = Portuguese
8Name = Portguese
Column8Width = 70

;Column9Name = 
;9Name =
;Column9Width = 0


;-----------------------------------------------------------------------------------------------------
;CREATE GUI:
;-----------------------------------------------------------------------------------------------------

;TO HIDE AHK ICON IN GUI UPPER LEFT CORNER
Gui +LastFound
DllCall("uxtheme\SetWindowThemeAttribute", "ptr", WinExist()
    , "int", 1, "int64*", 6 | 6<<32, "uint", 8)

Gui, Add, Button, x120 y10 %DefaultButtonSize% vButtonAddRow gButtonAddRow, Add Row
Gui, Add, Button, xp+81 yp %DefaultButtonSize% vButtonEditRow gButtonEditRow, Edit Row
Gui, Add, Button, xp+81 yp %DefaultButtonSize% vButtonDeleteRow gButtonDeleteRow, Delete Row
ButtonDeleteRow_TT := "Delete the selected row (Delete key).`nShift+Delete: no prompt."        ;ToolTip for the Delete button.
Gui, Add, Button, xp+81 yp %DefaultButtonSize% vButtonMoveUp gButtonMoveUp, Move &Up
ButtonMoveUp_TT := "Move the selected rows up one row (PageUp)"                    ;ToolTip for the Move Up button.
Gui, Add, Button, xp+81 yp %DefaultButtonSize% vButtonMoveDown gButtonMoveDown, &Move Down
ButtonMoveDown_TT := "Move the selected rows down one row (PageDown)"                ;ToolTip for the Move Down button.
;Gui, Add, ListView, x100 y40 w500 h200 vMainListView gMainListView Grid -Multi +SortHdr +LV0x4000 +AltSubmit, %Column1Name%|%Column2Name%|%Column3Name%|%Column4Name%|%Column5Name%|%Column6Name%|%Column7Name%|%Column8Name% ;LV0x4000 unfolds partially hidden items in the listview in the form of a tooltip, -Multi only allows one row to be focused at a time, and NoSortHdr disables sorting the listview when a column header is clicked.
Gui, Add, ListView, x120 y40 w500 h200 vMainListView gMainListView Grid -Multi +SortHdr +AltSubmit, %Column1Name%|%Column2Name%|%Column3Name%|%Column4Name%|%Column5Name%|%Column6Name%|%Column7Name%|%Column8Name% ;LV0x4000 unfolds partially hidden items in the listview in the form of a tooltip, -Multi only allows one row to be focused at a time, and NoSortHdr disables sorting the listview when a column header is clicked.


;SIDEBAR MENU
Gui, Font, Bold
Gui, Add, Text, x10 y50, Program
Gui, Font, Normal
Gui, Add, Text, x10 y75 vFAP gFAPClicked, Financial Assistance
Gui, Add, Text, x10 y100, Scholarship

Gui, Font, Bold
Gui, Add, Text, x10 y125, Process
Gui, Font, Normal
Gui, Add, Text, x10 y150, Application Process	
Gui, Add, Text, x10 y175, Consultation Process
Gui, Add, Text, x10 y200, Decision Process
Gui, Add, Text, x10 y225, Payment Process
Gui, Add, Text, x10 y250, Receipt Process
Gui, Add, Text, x10 y275, Closure Process

;Gui, Add, Text, x10 y65 w90 0x10  ;Horizontal Line > Etched Gray

gosub,filllist

    LV_ModifyCol()            ;Attempt to automatically set a column width for those columns where no default is specified.
    LV_ModifyCol(1, 60)    ;Set the default width for these columns.
    LV_ModifyCol(2, 80)
    LV_ModifyCol(3, 80)
    LV_ModifyCol(4, 200)
    LV_ModifyCol(5, 70)
    LV_ModifyCol(6, 70)
    LV_ModifyCol(7, 70)
    LV_ModifyCol(8, 70)
    LV_ModifyCol(9, "AutoHdr")


  ;LV_ModifyCol(1, "Sort")
  LV_Modify(LV_GetCount(), "Vis")     ;scrolls down



;If no name exists for a column, delete the column:
;if Column3Name := ""
;    LV_DeleteCol(3)
;if Column4Name := ""
;    LV_DeleteCol(4)
;if Column4Name := ""
;    LV_DeleteCol(4)
;if Column5Name := ""
;    LV_DeleteCol(5)
;if Column6Name := ""
;    LV_DeleteCol(6)
;if Column7Name := ""
;    LV_DeleteCol(7)
;if Column8Name := ""
;    LV_DeleteCol(8)


;Add the buttons along the bottom:
Gui, Add, Button, x212 y421  %DefaultButtonSize% vButtonOK gButtonOK Default, &OK
Gui, Add, Button, xp+81 yp %DefaultButtonSize% vButtonCancel gButtonCancel, &Cancel
Gui, Add, Button, xp+81 yp %DefaultButtonSize% vButtonApply gButtonApply, &Apply

;Show the GUI and set other options:
Gui, +Resize -MaximizeBox +MinSize411x132
Gui, Show, w1000 h500 , %MainWindowTitle%
OnMessage(0x200, "WM_MOUSEMOVE")        ;For the tooltips.
;Gui, Destroy

return


filllist:
Gui,1:default
Gui,1:Submit,nohide
Gui,1:ListView,MainListView
LV_Delete()
loop,read,%f1%
  {
  b1=
  b2=
  b3=
  b4=
  b5=
  b6=
  b7=
  b8=
  stringsplit,b,A_LoopReadLine,%d%,
  LV_Add("",b1,b2,b3,b4,b5,b6,b7,b8)
  }
Return


PrintLv:

ifexist,%f1%
   filedelete,%f1%
ControlGet,AA,List,,SysListView321,%MainWindowTitle%   ;<< the correct name of listview
stringreplace,A,AA,`t,%d%,all                          ;<< replaces TAB with Delimiter `;
stringreplace,A,A,`n,`r`n,all
fileappend,%A%,%F1%
return

;---------------------------------------------------------------------------------------------------------------------
;FAP CLICKED
;---------------------------------------------------------------------------------------------------------------------

FAPClicked:
	
	FAP := FAP

	;Clear Listview
	Gui,1:default
	Gui,1:Submit,nohide
	Gui,1:ListView,MainListView
	LV_Delete()

	;Repopulate Listview
	Gui,1:ListView,MainListView


loop,read,%f1%
  {
  b1=
  b2=
  b3=
  b4=
  b5=
  b6=
  b7=
  b8=
  stringsplit,b,A_LoopReadLine,%d%,
  ;MsgBox %b1%
  if b1 contains FAP
  LV_Add("",b1,b2,b3,b4,b5,b6,b7,b8)
  }


	Return

;---------------------------------------------------------------------------------------------------------------------
; ADD ROW BUTTON
;---------------------------------------------------------------------------------------------------------------------

    ButtonAddRow:
    Gui, AddRow:+Owner1                          		;Make the main window the owner of this window.
    Gui +Disabled                                		;Disable the main window.

;PROGRAM
    Gui, AddRow:Add, Text, x6 y8, %1Name%:       		;Adds the text control for the first column (see variable at very top for name).
    gosub, GetFocusedRowNumber                   		;See label at bottom.    
    Gui, AddRow:Add, Edit, x70 y6 w270 vAddRowEditCol1,         ;Creates the first blank Edit control.

;PROCESS
    Gui, AddRow:Add, Text, x6 y40, %2Name%:                	;Adds the text control for the second column (see variable at very top for name).
    Gui, AddRow:Add, Edit, x70 y38 w270 vAddRowEditCol2,    	;Creates the second blank Edit control.

;TYPE
    Gui, AddRow:Add, Text, x6 y72, %3Name%:                	;Adds the text control for the third column (see variable at very top for name).
    Gui, AddRow:Add, Edit, x70 y70 w270 vAddRowEditCol3,    	;Creates the third blank Edit control.

;DESCRIPTION
    Gui, AddRow:Add, Text, x6 y104, %4Name%:                	;Adds the text control for the fourth column (see variable at very top for name).
    Gui, AddRow:Add, Edit, x70 y102 w270 vAddRowEditCol4,    	;Creates the fourth blank Edit control.

;ENGLISH
    Gui, AddRow:Add, Text, x6 y136, %5Name%:               	;Adds the text control for the fifth column (see variable at very top for name).
    Gui, AddRow:Add, Edit, x70 y134 w270 h80 vAddRowEditCol5,    	;Creates the fifth blank Edit control.

;SPANISH
    Gui, AddRow:Add, Text, x6 y228, %6Name%:               	;Adds the text control for the sixth column (see variable at very top for name).
    Gui, AddRow:Add, Edit, x70 y226 w270 h80 vAddRowEditCol6,  ;Creates the sixth blank Edit control.

;RUSSIAN
    Gui, AddRow:Add, Text, x6 y320, %7Name%:               	;Adds the text control for the seventh column (see variable at very top for name).
    Gui, AddRow:Add, Edit, x70 y318 w270 h80 vAddRowEditCol7,  ;Creates the seventh blank Edit control.

;PORTUGUESE
    Gui, AddRow:Add, Text, x6 y412, %8Name%:               	;Adds the text control for the eight column (see variable at very top for name).
    Gui, AddRow:Add, Edit, x70 y410 w270 h80 vAddRowEditCol8,  ;Creates the eigth blank Edit control.

;OK BUTTON
    Gui, AddRow:Add, Button, x185 y500 %DefaultButtonSize% vAddRowButtonOK gAddRowButtonOK    Default, &OK    	;Adds the OK button (see label below).

;CANCEL BUTTON
    Gui, AddRow:Add, Button, x265 y500 %DefaultButtonSize% vAddRowButtonCancel gAddRowButtonCancel, &Cancel    		;Adds the Cancel button (see label below).

;GUI PARAMETERS
    Gui, AddRow: -MaximizeBox -MinimizeBox                    	;Removes the maximise and minimise buttons from the titlebar.
    Gui, AddRow:Show, w355 h535, Add Row                    	;Shows the AddRow dialogue and sets the window size and title.
    
    return

;---------------------------------------------------------------------------------------------------------------------
;ADD ROW OK BUTTON
;---------------------------------------------------------------------------------------------------------------------
    AddRowButtonOK:
    Gui, AddRow:Submit, NoHide        	;Submit the contents of the controls into their respective variables.
    gosub, CloseChildGui        	;See label at bottom.
    RowNumber := RowNumber + 1        	;Add 1 to %RowNumber% to insert it below the focused row instead of above it.
    LV_Insert(RowNumber, "", AddRowEditCol1, AddRowEditCol2, AddRowEditCol3, AddRowEditCol4, AddRowEditCol5, AddRowEditCol6, AddRowEditCol7, AddRowEditCol8)    ;Insert the new row with column fields from the variables attached to the Edit boxes in the "AddRow..." dialogue.
    return

;---------------------------------------------------------------------------------------------------------------------
;EDIT ROW BUTTON
;---------------------------------------------------------------------------------------------------------------------
    ;Create the "Edit Row" dialogue when the EditRow button is clicked.
    ;(basically the same as the "AddRow" dialogue except here the current contents of the row that is being edited are shown in the Edit controls instead of being blank):
    ButtonEditRow:
    Gui, 2:Submit
    Gui, 1:Default
    MouseGetPos, MouseX, MouseY             ;Gets the current location of the mouse
    MouseX := MouseX + 50
    Gui, EditRow:+Owner1
    Gui +Disabled
    Gui, EditRow:Add, Text, x6 y9, %1Name%:
    gosub, GetFocusedRowNumber
   
    LV_GetText(Col1Text, RowNumber, 1)        ;Gets the text in row number %RowNumber%, column 1 and saves it in %Col1Text%.
    LV_GetText(Col2Text, RowNumber, 2)        ;Gets the text in row number %RowNumber%, column 2 and saves it in %Col2Text%.
    LV_GetText(Col3Text, RowNumber, 3)        ;Gets the text in row number %RowNumber%, column 3 and saves it in %Col3Text%.
    LV_GetText(Col4Text, RowNumber, 4)        ;Gets the text in row number %RowNumber%, column 4 and saves it in %Col3Text%.
    LV_GetText(Col5Text, RowNumber, 5)        ;Gets the text in row number %RowNumber%, column 6 and saves it in %Col3Text%.
    LV_GetText(Col6Text, RowNumber, 6)        ;Gets the text in row number %RowNumber%, column 6 and saves it in %Col3Text%.
    LV_GetText(Col7Text, RowNumber, 7)        ;Gets the text in row number %RowNumber%, column 7 and saves it in %Col3Text%.
    LV_GetText(Col8Text, RowNumber, 8)        ;Gets the text in row number %RowNumber%, column 8 and saves it in %Col3Text%.
 
;PROGRAM   
    Gui, EditRow:Add, Text, x6 y8, %1Name%:
     gosub, GetFocusedRowNumber
    Gui, EditRow:Add, Edit, x70 y6 w270 vEditRowEditCol1, %Col1Text%    ;Creates the first Edit control and inserts the text from %Col1Text% into it (this works fine).

;PROCESS
    Gui, EditRow:Add, Text, x6 y40, %2Name%:
    Gui, EditRow:Add, Edit, x70 y38 w270 vEditRowEditCol2, %Col2Text%    ;Creates the second Edit control and inserts the text from %Col2Text% into it (this works fine).

;TYPE
    Gui, EditRow:Add, Text, x6 y72, %3Name%:
    Gui, EditRow:Add, Edit, x70 y70 w270 vEditRowEditCol3, %Col3Text%    ;Creates the third Edit control and inserts the text from %Col3Text% into it (this works fine).

;DESCRIPTION
    Gui, EditRow:Add, Text, x6 y104, %4Name%:
    Gui, EditRow:Add, Edit, x70 y102 w270 vEditRowEditCol4, %Col4Text%    ;Creates the fourth Edit control and inserts the text from %Col4Text% into it (this works fine).

;ENGLISH
    Gui, EditRow:Add, Text, x6 y136, %5Name%:
    Gui, EditRow:Add, Edit, x70 y134 w270 h80 vEditRowEditCol5, %Col5Text%    ;Creates the fifth Edit control and inserts the text from %Col5Text% into it (this works fine).

;SPANISH
    Gui, EditRow:Add, Text, x6 y228, %6Name%:
    Gui, EditRow:Add, Edit, x70 y226 w270 h80 vEditRowEditCol6, %Col6Text%    ;Creates the sixth Edit control and inserts the text from %Col6Text% into it (this works fine).

;RUSSIAN
    Gui, EditRow:Add, Text, x6 y320, %7Name%:
    Gui, EditRow:Add, Edit, x70 y318 w270 h80 vEditRowEditCol7, %Col7Text%    ;Creates the seventh Edit control and inserts the text from %Col7Text% into it (this works fine).

;PORTUGUESE
    Gui, EditRow:Add, Text, x6 y412, %8Name%:
    Gui, EditRow:Add, Edit, x70 y410 w270 h80 vEditRowEditCol8, %Col8Text%    ;Creates the eigth Edit control and inserts the text from %Col8Text% into it (this works fine).

;OK BUTTON
    Gui, EditRow:Add, Button, x185 y500 %DefaultButtonSize% vEditRowButtonOK gEditRowButtonOK Default, &OK

;CANCEL BUTTON
    Gui, EditRow:Add, Button, x265 y500 %DefaultButtonSize% vEditRowButtonCancel gEditRowButtonCancel, &Cancel

;GUI PARAMETERS
    Gui, EditRow: -MaximizeBox -MinimizeBox
    Gui, EditRow:Show,  w355 h535, Edit Row
    return

;---------------------------------------------------------------------------------------------------------------------
;EDIT ROW OK BUTTON
;---------------------------------------------------------------------------------------------------------------------
    EditRowButtonOK:        ;Same as the AddRowButtonOK label above except for the LV_Modify instead of LV_Insert.
    Gui, EditRow:Submit, NoHide
    gosub, CloseChildGui
    LV_Modify(RowNumber, "", EditRowEditCol1, EditRowEditCol2,EditRowEditCol3, EditRowEditCol4, EditRowEditCol5, EditRowEditCol6, EditRowEditCol7, EditRowEditCol8)
    return

;---------------------------------------------------------------------------------------------------------------------
;DELETE ROW BUTTON
;---------------------------------------------------------------------------------------------------------------------
    ;Create the Delete confirmation dialogue when the Delete button is pressed:
    ButtonDeleteRow:
    #IfWinActive, CAF Communication Templates
    Delete::
    #IfWinActive
    Gui, 1:Default
    gosub, GetFocusedRowNumber
    if RowNumber = 0    ;If there is no row selected in the listview, do nothing.
    return
    ;Menu, Tray, Icon, imageres.dll, 85    ;shell32.dll, 238 for Exclamation icon.
    Gui, DeleteRow:+Owner1            ;Make the main window the owner of this window.
    Gui +Disabled                ;Disable the main window.
    Gui, DeleteRow:Add, Picture, w-1 h32 x11 y11 Icon272, %A_WinDir%\System32\shell32.dll        ;Add the "Delete File" icon.
    Gui, DeleteRow:Add, Text, xp+48 yp, Are you sure you want to permanently delete this row?    ;Add "Are you sure...?" text.
    LV_GetText(Col1Text, RowNumber, 1)    ;Get the text in row number %RowNumber%, column 1 and save it in %Col1Text%.
   ; LV_GetText(Col2Text, RowNumber, 2)    ;Get the text in row number %RowNumber%, column 2 and save it in %Col2Text%.
   ; Gui, DeleteRow:Add, Text, xp+30 yp+18, %Col1Text%
   ; Gui, DeleteRow:Add, Text, xp yp+18, %Col2Text%
    ;~ Gui, DeleteRow:Default            ;Temporarily make this dialogue window the primary one in order to create a listview.
    ;~ Gui, DeleteRow:Add, ListView, xp y38 w283 r1 vDeleteRowListView +Grid -Hdr +LV0x4000, ;%Column1Name%|%Column2Name%    ;-Hdr removes column titles; +LV0x4000 unfolds partially hidden columns.
    ;~ LV_Add("", Col1Text, Col2Text)          ;Add the row that is going to be deleted.
    ;~ LV_ModifyCol(1, 163)
    ;~ LV_ModifyCol(2, 120)
    Gui, DeleteRow:Add, Button, x187 y72 %DefaultButtonSize% vDeleteRowButtonYes gDeleteRowButtonYes Default, &Yes    ;Add Yes button.
    Gui, DeleteRow:Add, Button, xp+81 yp %DefaultButtonSize% vDeleteRowButtonNo gDeleteRowButtonNo, &No        ;Add No button.
    Gui, DeleteRow: -MaximizeBox -MinimizeBox        ;Remove the minimise and maximise buttons in the titlebar.
    Gui, DeleteRow:Show, w350 h102, Delete Row        ;Show the GUI and set the window size.
    return

;---------------------------------------------------------------------------------------------------------------------
;DELETE ROW YES BUTTON
;---------------------------------------------------------------------------------------------------------------------
    DeleteRowButtonYes:
    #IfWinActive, Delete Row
    Delete::
    gosub,CloseChildGui
    LV_Delete(RowNumber)        ;Delete the row specified by %RowNumber% when Yes is pressed.
    #IfWinActive
    return
    ;DeleteRowButtonNo is at the bottom.


    #IfWinActive, CAF Communication Templates
    +Delete::            ;Delete the row specified by %RowNumber% and show no warning when shift is held down and Delete is pressed or clicked.
    #IfWinActive
    LV_Delete(RowNumber)
    return

;---------------------------------------------------------------------------------------------------------------------
;MOVE UP BUTTON
;---------------------------------------------------------------------------------------------------------------------
    ButtonMoveUp:          ;When PageUp is pressed or ButtonMoveUp is clicked, move the selected rows up one.
    PgUp::
    LV_MoveRow()    ;Refer to functions list below.
    return

;---------------------------------------------------------------------------------------------------------------------
;MOVE DOWN BUTTON
;---------------------------------------------------------------------------------------------------------------------
    ButtonMoveDown:                 ;When PageDown is pressed or ButtonMoveDown is clicked, move the selected rows down one.
    PgDn::
    LV_MoveRow(false)       ;Refer to functions list below.
    return

;---------------------------------------------------------------------------------------------------------------------
;OK BUTTON
;---------------------------------------------------------------------------------------------------------------------
    ButtonOK:
    ;Save to *.ini file and close the window.
    gosub,printlv
    ;ExitApp
    ;Gui, Destroy

;---------------------------------------------------------------------------------------------------------------------
;APPLY BUTTON
;---------------------------------------------------------------------------------------------------------------------   
	ButtonApply:
    ;Save to *.ini file but don't close the window.
    gosub,printlv
    return

;---------------------------------------------------------------------------------------------------------------------
;CANCEL BUTTON
;---------------------------------------------------------------------------------------------------------------------
    ;The Escape key and the Cancel and X buttons close the GUI and the script without saving.
    ButtonCancel:
    GuiClose:
    GuiEscape:
    ;ExitApp
	Gui, Destroy

;---------------------------------------------------------------------------------------------------------------------
;DOUBLE-CLICK RECORD IN LISTVIEW
;---------------------------------------------------------------------------------------------------------------------
MainListview:
if A_GuiEvent = DoubleClick     ;Double-clicking a row opens the Edit Row dialogue window.
gosub, ButtonEditRow
return

;---------------------------------------------------------------------------------------------------------------------
;RESIZE GUI IN RESPONSE TO USER GUI SIZE CHANGE
;---------------------------------------------------------------------------------------------------------------------
;Expand/shrink and move controls in response to the user's resizing of the window:
GuiSize:
if A_EventInfo = 1    ;The window has been minimized.  No action needed.
    return
GuiControl, Move, MainListView, % "W" . (A_GuiWidth - 14) . " H" . (A_GuiHeight - 73)    ;Otherwise, the window has been resized or maximized. Resize the control to match.

;Keep the OK/Cancel/Apply buttons at the bottom right corner and redraw them so they don't appear distorted:
GuiControl, Move, ButtonOK, % "x" . (A_GuiWidth -244) . "y" . (A_GuiHeight - 29)
GuiControl, Move, ButtonCancel, % "x" . (A_GuiWidth -163) . "y" . (A_GuiHeight - 29)
GuiControl, Move, ButtonApply, % "x" . (A_GuiWidth -82) . "y" . (A_GuiHeight - 29)
GuiControl, +Redraw, ButtonOK
GuiControl, +Redraw, ButtonCancel
GuiControl, +Redraw, ButtonApply
return


;====================End of Main Script=====================

;==========Labels Referred to in the Main Script===========
GetFocusedRowNumber:
Gui, 1:Default
RowNumber := "0"            ;Resets the %RowNumber% variable to zero.
RowNumber := LV_GetNext(RowNumber, "Focused")    ;Starts searching for the focused row in the listview at row #0 and stores the focused row in the variable %RowNumber%.
return

MakeOwnerDisableMain:
Gui, DeleteRow:+Owner1        ;Make the main window the owner of this window.
Gui +Disabled            ;Disable the main window.

;All of these Close, Cancel, etc. labels/controls simply close the open dialogue window without any further actions:
CloseChildGui:
EditRowButtonCancel:
EditRowGuiClose:
EditRowGuiEscape:
AddRowButtonCancel:
AddRowGuiClose:
AddRowGuiEscape:
DeleteRowButtonNo:
DeleteRowGuiClose:
DeleteRowGuiEscape:
Gui, 1:-Disabled    ;Re-enable the main window.
Gui Destroy        ;Destroy the dialogue window.
;Menu, Tray, Icon, imageres.dll, 90    ;Reset the tray/titlebar icon.
Gui, 1:Default
return
;=======End of Labels Referred to in the Main Script =======


;==============Functions=================

;This function came from http://www.autohotkey.com/board/topic/56396-techdemo-move-rows-in-a-listview/
LV_MoveRow(moveup = true) {
    ; Original by diebagger (Guest) from:
    ; http de.autohotkey.com /forum/viewtopic.php?p=58526#58526  Broken Link for safety
    ; Slightly Modifyed by Obi-Wahn
    If moveup not in 1,0
        Return    ; If direction not up or down (true or false)
    while x := LV_GetNext(x)    ; Get selected lines
        i := A_Index, i%i% := x
    If (!i) || ((i1 < 2) && moveup) || ((i%i% = LV_GetCount()) && !moveup)
        Return    ; Break Function if: nothing selected, (first selected < 2 AND moveup = true) [header bug]
                ; OR (last selected = LV_GetCount() AND moveup = false) [delete bug]
    cc := LV_GetCount("Col"), fr := LV_GetNext(0, "Focused"), d := moveup ? -1 : 1
    ; Count Columns, Query Line Number of next selected, set direction math.
    Loop, %i% {    ; Loop selected lines
        r := moveup ? A_Index : i - A_Index + 1, ro := i%r%, rn := ro + d
        ; Calculate row up or down, ro (current row), rn (target row)
        Loop, %cc% {    ; Loop through header count
            LV_GetText(to, ro, A_Index), LV_GetText(tn, rn, A_Index)
            ; Query Text from Current and Targetrow
            LV_Modify(rn, "Col" A_Index, to), LV_Modify(ro, "Col" A_Index, tn)
            ; Modify Rows (switch text)
        }
        LV_Modify(ro, "-select -focus"), LV_Modify(rn, "select vis")
        If (ro = fr)
            LV_Modify(rn, "Focus")
    }
}


;Tooltips on GUI controls (this function came from the Help file):
WM_MOUSEMOVE()
{
    static CurrControl, PrevControl, _TT  ; _TT is kept blank for use by the ToolTip command below.
    CurrControl := A_GuiControl
    If (CurrControl <> PrevControl and not InStr(CurrControl, " "))
    {
        ToolTip  ; Turn off any previous tooltip.
        SetTimer, DisplayToolTip, 1000
        PrevControl := CurrControl
    }
    return

    DisplayToolTip:
    SetTimer, DisplayToolTip, Off
    ToolTip % %CurrControl%_TT  ; The leading percent sign tell it to use an expression.
    SetTimer, RemoveToolTip, 3000
    return

    RemoveToolTip:
    SetTimer, RemoveToolTip, Off
    ToolTip
    return
}
;==========End of Functions===========

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], yabab33299 and 138 guests