Save checked checkboxes from listview to new .csv file Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
WalkerOfTheDay
Posts: 710
Joined: 24 Mar 2016, 03:01

Save checked checkboxes from listview to new .csv file

02 Dec 2019, 09:31

Hi guys,

I wrote below code (wip). This opens a csv file and puts in on the clipboard so that I can paste the data
into SAP Business One. It works perfectly.

Now I read in the documentation that you can add checkboxes, which I did.

My question is, would it be possible to save only the items where I put in a checkbox to a new .csv file ?

Please find an example .csv file attached.

Code: Select all

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

CoordMode, Pixel, Screen
CoordMode, Mouse, Screen
CoordMode, ToolTip, Screen

^1::
Reload

^e::
MsgBox, 4096,, Bye Bye !, 2

ExitApp

^3::

#NoEnv
No := 0
OrderColumn := 1 

FileSelectFile, MyFileName, 3, , Open de order, *.csv
if (MyFileName = "")
{
	MsgBox, Je hebt geen bestand gekozen !
	Reload
	Sleep, 2000
	Sleep, 2000
}
	
LineArray 	:= [] ; start with an empty Array
Artikel 		:= [] 
Omschrijving 	:= [] 
Lijstprijs	:= []
Nettoprijs	:= []
Aantal		:= []
CAP			:= []
Korting		:= []

loop, read, %MyFileName%
{
	LineNumber := A_Index
	;Loop, Parse, A_LoopReadLine, CSV (Doesn't work because of the ; delimiter)
	Loop, Parse, A_LoopReadLine, `;	
		LineArray[A_Index] := A_LoopField
	No++
	Artikel[No]		:= LineArray[1]
	Omschrijving[No] 	:= LineArray[2] 
	Lijstprijs[No]		:= LineArray[3]
	Nettoprijs[No]		:= LineArray[4]
	CAP[No]			:= LineArray[5]
	Aantal[No]		:= LineArray[6]
	Korting[No]		:= ""
	
	If !(Nettoprijs[No] = "")
		Korting[No] := "0,00"	; maak kortingsveld leeg als er een nettoprijs ingegeven wordt
}

Concat 	:= 
SendtoSAP :=

Loop, %No%
{
	SendtoSAP := SendtoSAP . Artikel[A_Index] . "`t" . Aantal[A_Index] . "`t`t" . Nettoprijs[A_Index] . "`t" . Korting[A_Index] . "`t`n"
	ClipBoard := ""
	ClipBoard := SendtoSAP
}

SplitPath, MyFileName, MyName

Gui Add, Text,	x34	y52 h23   , Bestandsnaam:
Gui Add, Text,	x155	y52 h23   , % MyName
Gui Add, Text,	x34	y27 h23, Aantal regels:
Gui Add, Text,	x155	y27 h23   , % No
Gui Add, ListView, Checked Grid x34 y90 r10 w650, Nr.|Art.nr|Omschrijving|Lijstprijs|Nettoprijs|CAP|Aantal
Gui Add, Button, gCopy vCopy, Kopieer order
Teller := 1
Loop, %No%
{
	;Gui Add, Text, x155           , % Omschrijving[A_Index]
	LV_Add(, Teller, Artikel[A_Index], Omschrijving[A_Index], Lijstprijs[A_Index], Nettoprijs[A_Index], CAP[A_Index], Aantal[A_Index])
	Teller++
	
}

LV_ModifyCol(1, "AutoHDR")
LV_ModifyCol(2, "AutoHDR")
LV_ModifyCol(3, "AutoHDR")
LV_ModifyCol(4, "AutoHDR Center")
LV_ModifyCol(5, "AutoHDR Center")
LV_ModifyCol(6, "AutoHDR Center")

Gui Show, x2086 y164 w750 h385, Order importeren
Return

GuiClose:
Gui, Destroy
return

Copy:
Clipboard := Clipboard ; Convert any copied files, HTML, or other formatted text to plain text.
ClipWait
GuiControl, Text, Copy, Gelukt !
return
Attachments
Order for client [email protected]
(153 Bytes) Downloaded 59 times
User avatar
WalkerOfTheDay
Posts: 710
Joined: 24 Mar 2016, 03:01

Re: Save checked checkboxes from listview to new .csv file

03 Dec 2019, 02:46

Found something that works for selected (highlighted) items, but I'm actually looking to
checked items that are checked. Any ideas ?

Code: Select all

GuiControl, Text, Copy, Gelukt !
ControlGet, SelectedItems, List, Selected, SysListView321
MsgBox, %SelectedItems%
garry
Posts: 3770
Joined: 22 Dec 2013, 12:50

Re: Save checked checkboxes from listview to new .csv file

03 Dec 2019, 09:31

goedenavond, sorry , just short , old basic example , Listview , save checked info , print only checked or all

Code: Select all

modified=20121021
NAME1=LV_Check_Example_%modified%
F1=%A_scriptdir%\LV_Check_TestFile.txt
F2=%A_scriptdir%\LV_All.txt
F3=%A_scriptdir%\LV_Selected.txt

Gui,1:default
Gui,1: +LastFound
Gui,1:Font,S10 cDefault, Verdana

;------- create a test-file ----

ifnotexist,%F1%
{
AA=
(Ltrim Join`r`n
Line1A;1AA;FOTO;1AAAA;1
Line2A;2BB;RADIO;2DDDD;0
Line3A;3BB;MUSIC;3DDDD;0
Line4A;4BB;TAPE;4DDDD;1
Line5A;5BB;MP3;5DDDD;1
)
Fileappend,%AA%`n,%F1%
}


LSW:=(T1+T2+T3+T4+20)    ;Listview width
GSW:=(LSW+30)            ;GUI      width

Gui,1:Add,Button,   x230  y430  w120  h25  gShowall       ,ShowAll
Gui,1:Add,Button,   x370  y430  w120  h25  gSelectAll     ,Select-All
Gui,1:Add,Button,   x500  y430  w120  h25  gDeselectAll   ,Deselect-All
Gui,1:Add,Button,x680  y470  w80   h25  gPrintlv       ,PrintLV      ;what you see
Gui,1:Add,Button,x780  y470  w120  h25  gPrintSelected ,PrintSelected

Gui,1:Add ,  Edit,   x200  y470  w70 h25 vTOT1 ,
Gui,1:Add ,  Edit,   x290  y470  w70 h25 vPOS1 ,

T1=600       ;column1 width
T2=50        ;column2 width
T3=100       ;column3 width
T4=100       ;column4 width

T1A:=T1
T2A:=T1+T2
T3A:=T1+T2+T3
T4A:=T1+T2+T3+T4

LSW:=(T1+T2+T3+T4+20)    ;Listview width
GSW:=(LSW+50)            ;GUI      width

Gui,1:Add,   Edit,   x10   y0  w%LSW%  h20  vSRC2  ,%F1%        ;show selected file
Gui,1:Add, ListView,checked x10 y30 h380 w%LSW%   grid +hscroll altsubmit vMLV1A gMLV1B, AA|BB|CC|DD
  LV_ModifyCol(1,T1)
  LV_ModifyCol(2,T2)
  LV_ModifyCol(3,T3)
  LV_ModifyCol(4,T4)

gosub,SB

Gui,1:Show, x2 y0 w%GSW% h510,%name1%
return
;-------------------------------

guiclose:
gosub,savechecked
exitapp
;-------------------------------

SB:
AA=
Gui,1:ListView,MLV1A
GuiControl,1:text,src2,%F1%
R=0
LV_Delete()
  loop,read,%F1%
  {
  C1=
  C2=
  C3=
  C4=
  C5=
  R++
  stringsplit,C,A_LoopReadLine,`;,
  if C5=1
     LV_Insert(R,"Check",C1,C2,C3,C4)
  else
     LV_Add("",C1,C2,C3,C4)
  }

GC:=LV_GetCount()
LV_Modify(LV_GetCount(), "Vis")    ;jumps to last row
LV_Modify(GC, "+Select +Focus")    ;focus last row
GuiControl,1:Text,TOT1,%GC%
GuiControl,1:Text,POS1,%R%           ;show position
return

;=================================================

SHOWALL:
gosub,sb
return
;-----------------------


;--------------- BLOCK SELECT DESELECT -------------
SELECTALL:
LV_Modify(0, "check")
return

DESELECTALL:
LV_Modify(0, "-check")
return
;---------------------------------------------------

PrintSelected:
Gui,submit,nohide
Gui,1:ListView, A1
;F3=LV_Selected.txt
ifexist,%F3%
  filedelete,%F3%
GS:=LV_GetCount()
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)
        Fileappend,%C1%`;%C2%`;%C3%`;%C4%`r`n,%F3%
        }
  }
ifexist,%f3%
    run,%F3%
return
;----------------------------------------------------


; Save List Checked
SaveChecked:
     K1=0
     K2=0
     filedelete,%F1%
     Loop % LV_GetCount()
       {
        K1++
        BX1=
        BX2=
        BX3=
        BX4=

        LV_GetText(BX1,A_INDEX,1)
        LV_GetText(BX2,A_INDEX,2)
        LV_GetText(BX3,A_INDEX,3)
        LV_GetText(BX4,A_INDEX,4)

        if K1=1
          K2 := LV_GetNext(K2,"checked")
        if (K1=K2)
          {
          Fileappend,%BX1%;%BX2%;%BX3%;%BX4%;1`r`n,%F1%
          K2 := LV_GetNext(K2,"checked")
          }
        else
          Fileappend,%BX1%;%BX2%;%BX3%;%BX4%;0`r`n,%F1%
        }
return
;------------ END BLOCK LV-1 checked 0/1 save ---------------------------


;============== PRINTLV =========================
PRINTLV:
Gui,1:submit,nohide
Gui,1:ListView, A1
ifexist,%F2%
  filedelete,%F2%

RF:=1
GD:=LV_GetCount()
 loop,%gd%
 {
    I2++
     LV_GetText(C1,RF,1)
     LV_GetText(C2,RF,2)
     LV_GetText(C3,RF,3)
     LV_GetText(C4,RF,4)
     Fileappend,%C1%`;%C2%`;%C3%`;%C4%`r`n,%F2%
     RF:=(RF+1)
  }
run,%F2%
return
;=============== END PRINTLV ===================


;-----------------------------------------------
MLV1B:
Gui,1:Submit,nohide
Gui,1:ListView,MLV1A
    RN:=LV_GetNext("C")
    RF:=LV_GetNext("F")
    GC:=LV_GetCount()

if A_GuiEvent=normal
    {
    LV_GetText(C1,a_eventinfo,1)
    GuiControl,1:Text,POS1,%RF%
    return
    }

if A_GuiEvent=doubleclick
    {
    LV_GetText(C1,a_eventinfo,1)
    GuiControl,1:Text,POS1,%RF%
    msgbox, 262208,Row=%a_eventinfo%, %C1% , 2
    return
    }
return
;-------------------------------------------------------------------


garry
Posts: 3770
Joined: 22 Dec 2013, 12:50

Re: Save checked checkboxes from listview to new .csv file

03 Dec 2019, 15:56

your script example , saves selected rows to a new file

Code: Select all

;-------- saved at Dienstag, 3. Dezember 2019 21:24:45 --------------
;;-------- https://www.autohotkey.com/boards/viewtopic.php?f=76&t=70363 ---
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetTitleMatchMode, 2
CoordMode, Pixel, Screen
CoordMode, Mouse, Screen
CoordMode, ToolTip, Screen
/*
^1::
Reload
^e::
MsgBox, 4096,, Bye Bye !, 2
ExitApp
^3::
*/

#NoEnv
No := 0
OrderColumn := 1 
FileSelectFile, MyFileName, 3, , Open de order, *.csv
if (MyFileName = "")
{
	MsgBox, Je hebt geen bestand gekozen !
	Reload
	Sleep, 2000
	Sleep, 2000
}
	
LineArray 	:= [] ; start with an empty Array
Artikel 		:= [] 
Omschrijving 	:= [] 
Lijstprijs	:= []
Nettoprijs	:= []
Aantal		:= []
CAP			:= []
Korting		:= []
loop, read, %MyFileName%
{
	LineNumber := A_Index
	;Loop, Parse, A_LoopReadLine, CSV (Doesn't work because of the ; delimiter)
	Loop, Parse, A_LoopReadLine, `;	
		LineArray[A_Index] := A_LoopField
	No++
	Artikel[No]		:= LineArray[1]
	Omschrijving[No] 	:= LineArray[2] 
	Lijstprijs[No]		:= LineArray[3]
	Nettoprijs[No]		:= LineArray[4]
	CAP[No]			:= LineArray[5]
	Aantal[No]		:= LineArray[6]
	Korting[No]		:= ""
	
	If !(Nettoprijs[No] = "")
		Korting[No] := "0,00"	; maak kortingsveld leeg als er een nettoprijs ingegeven wordt
}
Concat 	:= 
SendtoSAP :=
Loop, %No%
{
	SendtoSAP := SendtoSAP . Artikel[A_Index] . "`t" . Aantal[A_Index] . "`t`t" . Nettoprijs[A_Index] . "`t" . Korting[A_Index] . "`t`n"
	ClipBoard := ""
	ClipBoard := SendtoSAP
}
SplitPath, MyFileName, MyName
Gui Add, Text,	x34	y52 h23   , Bestandsnaam:
Gui Add, Text,	x155	y52 h23   , % MyName
Gui Add, Text,	x34	y27 h23, Aantal regels:
Gui Add, Text,	x155	y27 h23   , % No
Gui Add, ListView, Checked Grid x34 y90 r10 w650 vA1, Nr.|Art.nr|Omschrijving|Lijstprijs|Nettoprijs|CAP|Aantal
Gui Add, Button, gCopy vCopy, Kopieer order
Teller := 1
Loop, %No%
{
	;Gui Add, Text, x155           , % Omschrijving[A_Index]
	LV_Add(, Teller, Artikel[A_Index], Omschrijving[A_Index], Lijstprijs[A_Index], Nettoprijs[A_Index], CAP[A_Index], Aantal[A_Index])
	Teller++
	
}
LV_ModifyCol(1, "AutoHDR")
LV_ModifyCol(2, "AutoHDR")
LV_ModifyCol(3, "AutoHDR")
LV_ModifyCol(4, "AutoHDR Center")
LV_ModifyCol(5, "AutoHDR Center")
LV_ModifyCol(6, "AutoHDR Center")
Gui Show, x2086 y164 w750 h385, Order importeren
Return
GuiClose:
exitapp

copy:
Gui,submit,nohide
Gui,1:ListView, A1
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%
fnew=%a_scriptdir%\NewFile.csv
ifexist,%fnew%
   filedelete,%fnew%
Fileappend,%e%,%fnew%
run,notepad %fnew%
return
User avatar
WalkerOfTheDay
Posts: 710
Joined: 24 Mar 2016, 03:01

Re: Save checked checkboxes from listview to new .csv file

04 Dec 2019, 07:12

garry wrote:
03 Dec 2019, 15:56
your script example , saves selected rows to a new file
Spoiler
Thanks garry !

That's what I was looking for basically. There is one more thing that would be the holy grail, but that would probably be very hard:

I would be nice to be able to edit number of pieces (aantal) on the fly from the listview, but I think that will take advanced programming...
garry
Posts: 3770
Joined: 22 Dec 2013, 12:50

Re: Save checked checkboxes from listview to new .csv file

04 Dec 2019, 09:33

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
;=============================================
Last edited by garry on 04 Dec 2019, 11:28, edited 1 time in total.
User avatar
WalkerOfTheDay
Posts: 710
Joined: 24 Mar 2016, 03:01

Re: Save checked checkboxes from listview to new .csv file

04 Dec 2019, 09:46

Thanks again.

While this works, it isn't really convenient when you have a 200 line orderform and then have to edit them one
by one to change the quantity.

But I like the proof of concept :bravo:
garry
Posts: 3770
Joined: 22 Dec 2013, 12:50

Re: Save checked checkboxes from listview to new .csv file

04 Dec 2019, 11:30

modified script above
Formatted text depending columns width ( use non proportional font like 'Lucida Console' for text editor )
click PRINT and see formatted text in text editor , so maybe easy to modify 'Aantal' ( last column in this case )
User avatar
WalkerOfTheDay
Posts: 710
Joined: 24 Mar 2016, 03:01

Re: Save checked checkboxes from listview to new .csv file

06 Dec 2019, 04:34

garry wrote:
04 Dec 2019, 11:30
modified script above
Formatted text depending columns width ( use non proportional font like 'Lucida Console' for text editor )
click PRINT and see formatted text in text editor , so maybe easy to modify 'Aantal' ( last column in this case )
Thanks again. For modifying 'aantal' it does work indeed. I forgot to mention that we sometimes give our customers an
extra discount and then we need to modify the price as well.

I'm afraid if I let some of our users edit it, they will end up modifying the wrong column, or using a point instead of comma.

But I really appreciate you willingness to help me. Great !

I already have a program that let's me do al this, which another user made for me, but he wrote it in Python.
My knowledge of Python is to limited to make any changes to it.
User avatar
WalkerOfTheDay
Posts: 710
Joined: 24 Mar 2016, 03:01

Re: Save checked checkboxes from listview to new .csv file

06 Dec 2019, 08:47

garry wrote:
06 Dec 2019, 07:57
you want edit in listview only a column (?) ... search for > Listview cell editing ... or ask again
https://www.autohotkey.com/boards/search.php?keywords=listview+cell+editing
example from user 'just me' :
https://www.autohotkey.com/boards/viewtopic.php?f=76&t=20900&hilit=listview+cell+editing
Yes indeed. I want to use a couple of csv files as 'order forms' where our sales reps can select which
items they want to order for our clients. They should only be able to change the quantities, and be able
to at a nett prize which overrules the list price.

I'll have a look at those links when I can find the time.
just me
Posts: 9459
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Save checked checkboxes from listview to new .csv file  Topic is solved

11 Dec 2019, 04:34

To answer your PM:

Code: Select all

#NoEnv
SetBatchLines, -1
If (SubStr(A_AhkVersion, 1, 6) < "1.1.20") {
   MsgBox, 16, ERROR, Sorry, this script requires AHK 1.1.20+!
   ExitApp
}
; ----------------------------------------------------------------------------------------------------------------------
LV := "
(
1234567890|www.google.com|Row 1
2345678901|msdn.microsoft.com|Row 2
3456789012|www.autohotkey.com|Row 3
4567890123|de.autohotkey.com|Row 4
)"
; ----------------------------------------------------------------------------------------------------------------------
LVW := 610
Gui, Margin, 20, 20
Gui, Font, s10, Verdana
Gui, Add, Text, , In-cell editing for common ListView (restricted to columns 2 and 4)
Gui, Add, ListView, -Readonly y+10 w%LVW% Grid r4 gSubLV1 hwndHLV1 AltSubmit vLV1, Col 1|Col 2|Col 3|Col 4|Col 5|%A_Space%
Loop, Parse, LV, `n
{
   If (A_LoopField) {
      StringSplit, F, A_LoopField, |
      LV_Add("", F1, F2, F3, A_Index, A_Index)
   }
}
Loop, % LV_GetCount("Column")
   LV_ModifyCol(A_Index, "AutoHdr")
; Create a new instance of LV_InCellEdit for HLV1
ICELV1 := New LV_InCellEdit(HLV1)
; Restrict editable columns
ICELV1.SetColumns(2, 4)
Gui, Show, , In-Cell ListView Editing with DoubleClick %A_AhkVersion%
Return
; ----------------------------------------------------------------------------------------------------------------------
GuiClose:
GuiEscape:
ExitApp
; ----------------------------------------------------------------------------------------------------------------------
SubLV1:
; Check for changes
If (A_GuiEvent == "F") {
   If (ICELV1["Changed"]) {
      Msg := ""
      For I, O In ICELV1.Changed
         Msg .= "Row " . O.Row . " - Column " . O.Col . " : " . O.Txt
      ToolTip, % "Changes in " . A_GuiControl . "`r`n`r`n" . Msg
      SetTimer, KillToolTip, 2000
      ICELV1.Remove("Changed")
   }
}
Return
; ----------------------------------------------------------------------------------------------------------------------
KillToolTip:
   ToolTip
Return
; ----------------------------------------------------------------------------------------------------------------------
^F1::
ControlGet, Content, List, , , ahk_id %HLV1%
MsgBox, 0, ControlGet, %Content%
Return
; ----------------------------------------------------------------------------------------------------------------------
#Include Class_LV_InCellEdit.ahk
User avatar
WalkerOfTheDay
Posts: 710
Joined: 24 Mar 2016, 03:01

Re: Save checked checkboxes from listview to new .csv file

12 Dec 2019, 07:24

just me wrote:
11 Dec 2019, 04:34
To answer your PM:

Code: Select all

#NoEnv
SetBatchLines, -1
If (SubStr(A_AhkVersion, 1, 6) < "1.1.20") {
   MsgBox, 16, ERROR, Sorry, this script requires AHK 1.1.20+!
   ExitApp
}
; ----------------------------------------------------------------------------------------------------------------------
LV := "
(
1234567890|www.google.com|Row 1
2345678901|msdn.microsoft.com|Row 2
3456789012|www.autohotkey.com|Row 3
4567890123|de.autohotkey.com|Row 4
)"
; ----------------------------------------------------------------------------------------------------------------------
LVW := 610
Gui, Margin, 20, 20
Gui, Font, s10, Verdana
Gui, Add, Text, , In-cell editing for common ListView (restricted to columns 2 and 4)
Gui, Add, ListView, -Readonly y+10 w%LVW% Grid r4 gSubLV1 hwndHLV1 AltSubmit vLV1, Col 1|Col 2|Col 3|Col 4|Col 5|%A_Space%
Loop, Parse, LV, `n
{
   If (A_LoopField) {
      StringSplit, F, A_LoopField, |
      LV_Add("", F1, F2, F3, A_Index, A_Index)
   }
}
Loop, % LV_GetCount("Column")
   LV_ModifyCol(A_Index, "AutoHdr")
; Create a new instance of LV_InCellEdit for HLV1
ICELV1 := New LV_InCellEdit(HLV1)
; Restrict editable columns
ICELV1.SetColumns(2, 4)
Gui, Show, , In-Cell ListView Editing with DoubleClick %A_AhkVersion%
Return
; ----------------------------------------------------------------------------------------------------------------------
GuiClose:
GuiEscape:
ExitApp
; ----------------------------------------------------------------------------------------------------------------------
SubLV1:
; Check for changes
If (A_GuiEvent == "F") {
   If (ICELV1["Changed"]) {
      Msg := ""
      For I, O In ICELV1.Changed
         Msg .= "Row " . O.Row . " - Column " . O.Col . " : " . O.Txt
      ToolTip, % "Changes in " . A_GuiControl . "`r`n`r`n" . Msg
      SetTimer, KillToolTip, 2000
      ICELV1.Remove("Changed")
   }
}
Return
; ----------------------------------------------------------------------------------------------------------------------
KillToolTip:
   ToolTip
Return
; ----------------------------------------------------------------------------------------------------------------------
^F1::
ControlGet, Content, List, , , ahk_id %HLV1%
MsgBox, 0, ControlGet, %Content%
Return
; ----------------------------------------------------------------------------------------------------------------------
#Include Class_LV_InCellEdit.ahk
Thank you !

I tested your code and it does what I'm looking for. Now I'm going to try to implement it in my own code
(when I can find the time :) ).

If I have any questions, I'll post it here, is that okay ?
User avatar
WalkerOfTheDay
Posts: 710
Joined: 24 Mar 2016, 03:01

Re: Save checked checkboxes from listview to new .csv file

23 Dec 2019, 06:18

just me wrote:
12 Dec 2019, 10:15
Ok!
Okay here goes, I have more questions but this is one I'm working on right now.
I would like to execute the code LV_modify(O.Row, "Col4", "0,00") Only
when a Nett price is inputted. The nett price is in Column 5.

Code: Select all

SubLV1:
; Check for changes
If (A_GuiEvent == "F")
{
	If (ICELV1 ["Changed"])
	{
		Msg := ""
		For I, O In ICELV1.Changed
			Msg .= "Row " . O.Row . " - Column " . O.Col ; . ": " . O.Txt
		ToolTip, % "Changes in " . A_GuiControl . "`r`n`r`n" . Msg
		SetTimer, KillToolTip, 20000
		ICELV1.Remove("Changed")
		
		LV_modify(O.Row, "Col4", "0,00") ; Set list price (Column4) to zero when Nett price is inputted
		
	}
}
just me
Posts: 9459
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Save checked checkboxes from listview to new .csv file

24 Dec 2019, 06:36

Code: Select all

; ----------------------------------------------------------------------------------------------------------------------
SubLV1:
; Check for changes
If (A_GuiEvent == "F") {
   If (ICELV1["Changed"]) { ; no space !!!
      GuiControl, -g, LV1 ; deactivate th g-label
      Msg := ""
      For Each, Cell In ICELV1.Changed {
         If (Cell.Col = 5) {  ; Nett price changed
            Val := StrReplace(Cell.Txt, ",")
            If Val Is Integer
               If (Val > 0)
                  LV_modify(Cell.Row, "Col4", "0,00") ; Set list price (Column4) to zero when Nett price is inputted
         }
         Msg .= "Row " . Cell.Row . " - Column " . Cell.Col . " : " . Cell.Txt
      }
      ToolTip, % "Changes in " . A_GuiControl . "`r`n`r`n" . Msg
      SetTimer, KillToolTip, 2000
      ICELV1.Remove("Changed")
      GuiControl, +g%A_ThisLabel%, LV1 ; re-activate th g-label
   }
}
Return
; ----------------------------------------------------------------------------------------------------------------------
KillToolTip:
   ToolTip
Return
*not tested*

:xmas:
User avatar
WalkerOfTheDay
Posts: 710
Joined: 24 Mar 2016, 03:01

Re: Save checked checkboxes from listview to new .csv file

30 Dec 2019, 02:58

just me wrote:
24 Dec 2019, 06:36

Code: Select all

; ----------------------------------------------------------------------------------------------------------------------
SubLV1:
; Check for changes
If (A_GuiEvent == "F") {
   If (ICELV1["Changed"]) { ; no space !!!
      GuiControl, -g, LV1 ; deactivate th g-label
      Msg := ""
      For Each, Cell In ICELV1.Changed {
         If (Cell.Col = 5) {  ; Nett price changed
            Val := StrReplace(Cell.Txt, ",")
            If Val Is Integer
               If (Val > 0)
                  LV_modify(Cell.Row, "Col4", "0,00") ; Set list price (Column4) to zero when Nett price is inputted
         }
         Msg .= "Row " . Cell.Row . " - Column " . Cell.Col . " : " . Cell.Txt
      }
      ToolTip, % "Changes in " . A_GuiControl . "`r`n`r`n" . Msg
      SetTimer, KillToolTip, 2000
      ICELV1.Remove("Changed")
      GuiControl, +g%A_ThisLabel%, LV1 ; re-activate th g-label
   }
}
Return
; ----------------------------------------------------------------------------------------------------------------------
KillToolTip:
   ToolTip
Return
*not tested*

:xmas:
Thanks again. Sorry for the late reply. Didn't do any coding during the holidays :)

I'm getting this error message:

Code: Select all

Warning in #include file "C:\AHK-Studio-master\Projects\Class_LV_InCellEdit.ahk":
     This local variable has the same name as a global variable.

Specifically: Each  (in function LV_InCellEdit.SetColumns)

	Line#
	157: if (This["Columns"]) && (!This.Columns[Col - 1])  
	158: Return,False
	159: if !(DllCall("SendMessage", "Ptr", H, "UInt", 0x101D, "Ptr", Col - 1, "Ptr", 0, "Int") > 0)  
	160: Return,False
	161: This.DoubleClick(--Row, --Col)  
	162: Return,True
	163: }
--->	171: {
	172: if !(H := This.HWND)  
	173: Return,False
	174: This.Delete("Columns")  
	175: if (ColNumbers.MinIndex() = "")  
	176: Return,True
	177: ColCount := DllCall("SendMessage", "Ptr", This.HHDR, "UInt", 0x1200, "Ptr", 0, "Ptr", 0, "Int")
	178: Cols := []

For more details, read the documentation for #Warn.
just me
Posts: 9459
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Save checked checkboxes from listview to new .csv file

30 Dec 2019, 06:15

It's just a warning:
LocalSameAsGlobal: Before the script starts to run, display a warning for each undeclared local variable which has the same name as a global variable. This is intended to prevent errors caused by forgetting to declare a global variable inside a function before attempting to access it. If the variable really was intended to be local, a declaration such as local x or static y can be used to suppress the warning. This warning is never shown for variables inside a force-local function.

Code: Select all

#Warn
#Warn LocalSameAsGlobal, Off
or rename Each in SubLV.
User avatar
WalkerOfTheDay
Posts: 710
Joined: 24 Mar 2016, 03:01

Re: Save checked checkboxes from listview to new .csv file

30 Dec 2019, 07:50

just me wrote:
30 Dec 2019, 06:15
It's just a warning:
LocalSameAsGlobal: Before the script starts to run, display a warning for each undeclared local variable which has the same name as a global variable. This is intended to prevent errors caused by forgetting to declare a global variable inside a function before attempting to access it. If the variable really was intended to be local, a declaration such as local x or static y can be used to suppress the warning. This warning is never shown for variables inside a force-local function.

Code: Select all

#Warn
#Warn LocalSameAsGlobal, Off
or rename Each in SubLV.
Okay I see. Thanks. It does indeed work.
Would there also be some way to format the nett price with a comma when the users inputs a dot ? And then have 2 decimals ?

I was thinking something like this, but it doesn't work:

Code: Select all

      For Each, Cell In ICELV1.Changed {
         If (Cell.Col = 5) {  ; Nett price changed
            Val := StrReplace(Cell.Txt, ",")
            If Val Is Integer
               If (Val > 0)
			{
				LV_modify(Cell.Row, "Col4", "0,00") ; Set list price (Column4) to zero when Nett price is inputted
				
				Nettoprijs := StrReplace(Nettoprijs, ".", ",") ; replace dot with comma ; <<<<< added
				LV_modify(Cell.Row, "Col5", Nettoprijs) ; <<<<< added
			}
                  
         }

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: ArkuS, Ineedhelplz and 226 guests