again an old basic example , Listview = ADD-new / MODIFY / DELETE ( multiple rows ) / Formatted text depending columns width ( use non proportionel font like Lucida Console )
Code: Select all
;-https://www.autohotkey.com/boards/viewtopic.php?f=76&t=70363
MODIFIED=20191204/2
;CREATED =20111228
;-- LISTVIEW = ADDNEW -MODIFY -DELETE multiple -Formatted Text
;--------------------------------------------------
#warn
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%
SetBatchLines -1
filename1:=modified . " ADD-MODIFY-DELETE multiple Edit=RightClick DELETE=DEL"
Gui,1:default
Gui,1: -DPIScale
SS_REALSIZECONTROL := 0x40
;transform,S,chr,32 ;-- SPACE is the delimiter
;transform,S,chr,165 ;-- ANSI YEN is the delimiter
;S=, ;-- COMMA is the delimiter
s:=";"
;--- create a test-file ----
F1=testbasic.csv
ifnotexist,%f1%
{
e4x=
(Ltrim Join`r`n
PS4;Sony Playstation 4;99,99;;250,00;5
XBONE;XBox One;119,95;;250,00;3
REDMINOTE7;Xiaomi Redmi Note 7;75,00;;165,00;3
BP1;Red Ballpoint;0,60;;1,50;20
)
Fileappend,%e4x%`r`n,%f1%
}
;-----------------------------
T1=100 ;-- width column
T2=200
T3=250
T4=250
T5=250
T6=250
T7=100
tot:=(T1+T2+T3+T4+T5+T6+T7+50) ;-- width listview
xpos=110
headerx= Nr.|Art.nr|Omschrijving|Lijstprijs|Nettoprijs|CAP|Aantal
;- how many columns ( see : without numbering )
stringsplit,total,headerx,`|
total:=(total0-1)
Gui,1:Font,S13 CDefault,Lucida Console
Gui,1:Add, ListView,checked backgroundteal csilver grid r10 x%xpos% y0 w%tot% +hscroll altsubmit gLW2 vLV1,%headerx%
;LV_ModifyCol() ;-- fit automatic size
LV_ModifyCol(1,T1) ;-- size
LV_ModifyCol(2,T2)
LV_ModifyCol(3,T3)
LV_ModifyCol(4,T4)
LV_ModifyCol(5,T5)
LV_ModifyCol(6,T6)
LV_ModifyCol(7,T7)
LV_ModifyCol(4, "Integer")
LV_ModifyCol(5, "Integer")
LV_ModifyCol(6, "Integer")
LV_ModifyCol(7, "Integer")
Gui,1:Add,Button,gAddUrl x5 y420 w120 h35,ADD
Gui,1:Add,Button,gCopy x150 y420 w260 h35,COPY_SELECTED
Gui,1:Add,Button,gPRINT2 x450 y420 w260 h35,PRINT
gw:=xpos+tot+70
Gui,1:Show,x0 y0 w%gw% h470,%filename1%
gosub,lb
return
;=================================================================================================================
Guiclose:
exitapp
copy:
Gui,submit,nohide
Gui,1:ListView, LV1
GS:=LV_GetCount()
i2=0
e:=""
RNM =0
loop,%gs%
{
I2++
RNM := LV_GetNext(RNM,"checked")
if not RNM
break
else
{
LV_GetText(C1,RNM,1)
LV_GetText(C2,RNM,2)
LV_GetText(C3,RNM,3)
LV_GetText(C4,RNM,4)
LV_GetText(C5,RNM,5)
LV_GetText(C6,RNM,6)
LV_GetText(C7,RNM,7)
e .= C1 . ";" . C2 . ";" C3 . ";" . C4 . ";" . C5 . ";" C6 . ";" . C7 . "`r`n"
}
}
clipboard:=e
msgbox,%clipboard%
if e=
{
msgbox, 262208,EMPTY ,Checkbox Nothing selected
return
}
fnew=%a_scriptdir%\NewFile.csv
ifexist,%fnew%
filedelete,%fnew%
Fileappend,%e%,%fnew%
run,notepad %fnew%
return
;----------------------------------------
;----------------------------------------
LB:
Gui,1:default
LV_Delete()
Teller := 1
loop,read,%F1%
{
LR:=A_LoopReadLine
if LR=
continue
;stringreplace,LR,LR,",,all
;LR:=RegExReplace(LR,"\x20{2,}"," ") ;-- allow only on space
LR=%LR% ;-- remove leading space
stringsplit,C,LR,%s% ;-- split with delimiter
LV_Add("",teller,C1,C2,C3,C4,C5,C6)
teller++
}
LV_Modify(LV_GetCount(), "Vis") ;-- scrolls to last line
return
;==============================================================
;================= ADD-NEW ====================================
AddUrl:
Gui,2:Font, S10 CDefault , FixedSys
;headerx= Nr.|Art.nr|Omschrijving|Lijstprijs|Nettoprijs|CAP|Aantal
;Gui,2:Add,Text, x1 y5 w80 h20, AA
;Gui,2:Add,Edit, x80 y5 w500 h20 vA21, %A21%
Gui,2:Add,Text, x1 y30 w80 h20, ART.NR
Gui,2:Add,Edit, x80 y30 w500 h20 vA22, %A22%
Gui,2:Add,Text, x1 y60 w80 h20, Omschrijwing
Gui,2:Add,Edit, x80 y60 w500 h20 vA23, %A23%
Gui,2:Add,Text, x1 y90 w80 h20, Lijstprijs
Gui,2:Add,Edit, x80 y90 w500 h20 vA24, %A24%
Gui,2:Add,Text, x1 y120 w80 h20, Nettoprijs
Gui,2:Add,Edit, x80 y120 w500 h20 vA25, %A25%
Gui,2:Add,Text, x1 y150 w80 h20, CAP
Gui,2:Add,Edit, x80 y150 w500 h20 vA26, %A26%
Gui,2:Add,Text, x1 y180 w80 h20, Aantal
Gui,2:Add,Edit, x80 y180 w500 h20 vA27, %A27%
Gui,2:Add, Button, x550 y210 w40 h25, OK
Gui,2:Show, x2 y550 w600 h250, ADD_NEW
return
;---------------------------------------
2GuiClose:
2GuiEscape:
return
2ButtonOK:
Gui,2:submit
if A22=
{
Gui,2: Destroy
return
}
FILEAPPEND, %A22%%s%%A23%%s%%A24%%s%%A25%%s%%A26%%s%%A27%`r`n,%F1%
Gui,2: Destroy
GoSub, LB ;-- update LV
return
;============================================================
;============================================================
LW2:
Gui, Submit,nohide
Gui,1:ListView, LV1
;----------------------------------
if A_GuiEvent = Normal
{
LV_GetText(C1,A_EventInfo,1)
LV_GetText(C2,A_EventInfo,2)
LV_GetText(C3,A_EventInfo,3)
LV_GetText(C4,A_EventInfo,4)
LV_GetText(C5,A_EventInfo,5)
LV_GetText(C6,A_EventInfo,6)
LV_GetText(C7,A_EventInfo,7)
RN:=LV_GetNext("C")
RF:=LV_GetNext("F")
GC:=LV_GetCount()
}
;----------------------------
;=================== MODIFY ============
if A_GuiEvent = RightClick
{
LV_GetText(C1,A_EventInfo,1)
LV_GetText(C2,A_EventInfo,2)
LV_GetText(C3,A_EventInfo,3)
LV_GetText(C4,A_EventInfo,4)
LV_GetText(C5,A_EventInfo,5)
LV_GetText(C6,A_EventInfo,6)
LV_GetText(C7,A_EventInfo,7)
RN:=LV_GetNext("C")
RF:=LV_GetNext("F")
GC:=LV_GetCount()
GuiControl,3:Focus,Name
Gui,3:Font, S10 CDefault , FixedSys
;Gui,3:Add,Text, x1 y5 w80 h20, AA
;Gui,3:Add,Edit, x80 y5 w500 h20 vA31, %C1%
Gui,3:Add,Text, x1 y30 w80 h20, ART.NR
Gui,3:Add,Edit, x80 y30 w500 h20 vA32, %C2%
Gui,3:Add,Text, x1 y60 w80 h20, Omschrijving
Gui,3:Add,Edit, x80 y60 w500 h20 vA33, %C3%
Gui,3:Add,Text, x1 y90 w80 h20, Lijstprijs
Gui,3:Add,Edit, x80 y90 w500 h20 vA34, %C4%
Gui,3:Add,Text, x1 y120 w80 h20, Nettoprijs
Gui,3:Add,Edit, x80 y120 w500 h20 vA35, %C5%
Gui,3:Add,Text, x1 y150 w80 h20, CAP
Gui,3:Add,Edit, x80 y150 w500 h20 vA36, %C6%
Gui,3:Add,Text, x1 y180 w80 h20, Aantal
Gui,3:Add,Edit, x80 y180 w500 h20 vA37, %C7%
Gui,3:Add, Button, x550 y210 w40 h25, OK
Gui,3:Show, x2 y550 w600 h250, MODIFY
return
;---------------------------------------
3GuiClose:
3GuiEscape:
Gui, 3:Destroy
return
3ButtonOK:
Gui,3:submit
FileRead, FileContent, %F1%
FileDelete, %F1%
StringReplace, FileContent, FileContent, %C2%%s%%C3%%s%%C4%%s%%C5%%s%%C6%%s%%C7% , %A32%%s%%A33%%s%%A34%%s%%A35%%s%%A36%%s%%A37%
FileAppend, %FileContent%, %F1%
GoSub, LB
Goto,3guiclose
}
;=====================================================
;============= DELETE multiple marked rows DEL-Key ===========
;--- user Thalon http://de.autohotkey.com/forum/post-471.html#471
if A_GuiEvent=K
{
GetKeyState,state,DEL
if state=D
{
C1 =
RF = 0
RFL =
Loop
{
RF:=LV_GetNext(RF)
if RF=0
{
;msgbox,Select a row
break
}
RFL = %RF%|%RFL%
LV_GetText(C1_Temp, RF, 1)
C1 = %C1%`n%C1_Temp%
}
if C1 !=
{
msgbox, 262436,Delete,Want you really delete COLUMNS %C1% ?
IfMsgBox,No
Return
Else
{
Loop, parse, RFL, |
LV_Delete(A_LoopField)
filedelete,%F1%
Loop % LV_GetCount()
{
BX1=
BX2=
BX3=
BX4=
BX5=
BX6=
BX7=
LV_GetText(BX1,A_INDEX,1)
LV_GetText(BX2,A_INDEX,2)
LV_GetText(BX3,A_INDEX,3)
LV_GetText(BX4,A_INDEX,4)
LV_GetText(BX5,A_INDEX,5)
LV_GetText(BX6,A_INDEX,6)
LV_GetText(BX7,A_INDEX,7)
fileappend,%BX2%%s%%BX3%%s%%BX4%%s%%BX5%%s%%BX6%%s%%BX7%`r`n,%F1%
}
}
C1=
C2=
C3=
C4=
C5=
C6=
C7=
}
return
}
}
return
;===================================================
;============ case-1 PRINT_WYS Formatted text ====================
print2:
Gui,1:submit,nohide
;-- check maximal lenght from each column ---
FilePrint=%a_desktop%\Testbasic_%a_now%.csv
ifexist,%fileprint%
filedelete,%fileprint%
ControlGet, Listx, List, , SysListView321,%filename1%
stringreplace,listx,listx,`t,%s%,all
ed:=""
;- remove here the first column ( numbering )
loop,parse,listx,`n,`r
{
x=%a_loopfield%
i=0
loop,parse,x,%s%
{
i++
y=%a_loopfield%
if I=1
continue
ed .= y . s
}
stringtrimright,ed,ed,1
ed := ed . "`r`n"
}
listx2=%ed%
;msgbox,%listx2%
tx:=""
loop,%total%
T%a_index%:=0
loop,%total%
L%a_index%:=0
Loop,parse,listx2,`n,`r
{
lr=%a_loopfield%
if lr=
continue
i=0
loop,%total% ;- get max lenght from x columns
{
i++
StringSplit,A,lr,%s%
stringlen,L%i%,A%i%
if (T%i%<L%i%)
T%i%:=(L%i%+1) ;-maximal lenght columnX+1
}
}
;- x columns
loop,%total%
Tx .= "{:" . T%a_index% . "}" . s
stringtrimright,tx,tx,1
loop,%total%
a%a_index%:=""
lr=
e:=""
Loop, parse,listx2, `n,`r
{
lr=%a_loopfield%
if lr=
continue
a :=StrSplit(lr,s )
e .= Format(tx . "`r`n",a*)
}
fileappend,%e%,%fileprint%
run,notepad %fileprint%
e=
a=
listx=
listx2=
return
;=============================================