checkbox status of listview on fly?

Get help with using AutoHotkey and its commands and hotkeys
JaxD
Posts: 9
Joined: 28 Jul 2019, 01:21

checkbox status of listview on fly?

16 Aug 2019, 10:11

Hi,
searched the board but could not find anything similar.

is there a way to check the status of a checkbox in a listview instantly? i would like to start a program when i check and stop a programm when i uncheck the box


with normal checkboxes i can do that because the checkbox has a separate control but not in listview


with this code is is possible to check the status of the checboxes BUT unly AFTER a keystroke or button label, but i want to do this "on fly"


Code: Select all

ButtonCheck::
Loop % LV_GetCount()
{
LV_GetText(Name, A_Index)
	  RowNumber := A_Index           ;get first selected row
    RowChecked := LV_GetNext(RowNumber - 1 , "Checked" )
    If ( RowNumber = RowChecked )
	Msgbox %Name%
}
return

thanks in advance
awel20
Posts: 211
Joined: 19 Mar 2018, 14:09

Re: checkbox status of listview on fly?

16 Aug 2019, 12:19

You can use the AltSubmit option when creating the ListView, and that will allow you to monitor the "G-Label Notifications (Secondary)." If A_GuiEvent contains I then an item was changed. In that case, ErrorLevel will contain C if the row was checked and c if the row was unchecked.

Code: Select all

Gui, Add, ListView, vMyListView gMyListView AltSubmit Checked, Col 1|Col 2|Col 3
Loop, 3
	LV_Add(, "test 1 " A_Index, "test 2 " A_Index, "test 3 " A_Index)
Loop, 3
	LV_ModifyCol(A_Index)
Gui, Show
return

MyListView:
	if (A_GuiEvent == "I")
	{
		if InStr(ErrorLevel, "C", true)
			MsgBox % "Row "  A_EventInfo " was checked."
		else if InStr(ErrorLevel, "c", true)
			MsgBox % "Row "  A_EventInfo " was unchecked."
	}
return

GuiClose:
ExitApp
JaxD
Posts: 9
Joined: 28 Jul 2019, 01:21

Re: checkbox status of listview on fly?

16 Aug 2019, 14:28

thanks a lot. and not only for the code but also for the explanation.
JaxD
Posts: 9
Joined: 28 Jul 2019, 01:21

Re: checkbox status of listview on fly?

17 Aug 2019, 04:14

Me again ,

it_S really a pain in the ass to handle checkboxes in a listview. Mostly because they have not a separate guicontrol and obviosly my "listview skills" aren't that goood! ^^

My current script works good, butr now i have trounble to save the check status of my gui in an ini file, becvause i really do not have a clue how to retrive the check/uncheck status of each row! here is my code:


Code: Select all

MyListView:

if (A_GuiEvent == "I")
    {
    if InStr(ErrorLevel, "C", true)
        {
        ;MsgBox % "Row "  A_EventInfo " was checked."
         LV_GetText(RowText, A_EventInfo)
         SelectedFile=%searchDIR%\%RowText%
         Run, %SelectedFile%
        }
    else if InStr(ErrorLevel, "c", true)
        {
        ;MsgBox % "Row "  A_EventInfo " was unchecked."
         LV_GetText(RowText, A_EventInfo)
         SelectedFile=%searchDIR%\%RowText%
	ScriptName := RowText 
	PID := GetScriptPID(ScriptName)
	;MsgBox, 0, The PID, % ScriptName . " - " . GetScriptPID(ScriptName)
	Process, Close , %PID%
now i have to iniwrite the check statsu for every row and iniread it on the autoexecute part of my script, so the script can recognize if an other script should be running or not at the start.

thanks.


edit:

now i have the info i need stored in the ini file but how i can INIWRITE ist on the start that the listview can handle the checkbox status and start the programms/scripts?

Code: Select all

if (A_GuiEvent == "I")
    {
    if InStr(ErrorLevel, "C", true)
        {
        ;MsgBox % "Row "  A_EventInfo " was checked."
        LV_GetText(RowText, A_EventInfo)
        SelectedFile=%searchDIR%\%RowText%
        Run, %SelectedFile%
        cb_status = 1
	IniWrite, %cb_status%, ScriptManager.ini, Checkbox Status, %ScriptName%

        }
    else if InStr(ErrorLevel, "c", true)
        {

        ;MsgBox % "Row "  A_EventInfo " was unchecked."
        LV_GetText(RowText, A_EventInfo)
        SelectedFile=%searchDIR%\%RowText%

        ScriptName := RowText 
        PID := GetScriptPID(ScriptName)
        ;MsgBox, 0, The PID, % ScriptName . " - " . GetScriptPID(ScriptName)
        Process, Close , %PID%
        cb_status = 0
        IniWrite, %cb_status%, ScriptManager.ini, Checkbox Status, %ScriptName%
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: checkbox status of listview on fly?

17 Aug 2019, 04:49

This is a sample on how to save/retrieve the check status of a listview:

Code: Select all

IniRead, chk, temp.ini, ListView, checked, 0
if (chk <> "0")
   chkArr := StrSplit(chk,",")
Gui, Add, ListView, vMyListView AltSubmit Checked, Data
Loop, 5  {
	LV_Add(, "Data " A_Index)
}
for k, v in chkArr
   LV_Modify(v, "Check")
Gui, Show
return

Save:   
   RowNumber := 0, str := ""
   Loop % LV_GetCount() {
       RowNumber := LV_GetNext(RowNumber, "Checked")
       if not RowNumber
           break    
       str .= str ? "," RowNumber : RowNumber
   }
   IniWrite, %str%, temp.ini, ListView, checked
return

GuiClose:
GuiEscape:
*esc::
   gosub Save    
   ExitApp
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
User avatar
hasantr
Posts: 780
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: checkbox status of listview on fly?

11 Oct 2019, 15:22

Odlanir wrote:
17 Aug 2019, 04:49
str .= str ? "," RowNumber : RowNumber
What does the colon and the question mark tell you in this statement? Why are they there?
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: checkbox status of listview on fly?

11 Oct 2019, 15:46

It's a ternary operator. Is equivalent to this:

Code: Select all

If (str != "")  
   str := str "," RowNumber
else    
   str := RowNumber
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
User avatar
hasantr
Posts: 780
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: checkbox status of listview on fly?

12 Oct 2019, 00:09

Odlanir wrote:
11 Oct 2019, 15:46
It's a ternary operator. Is equivalent to this:

Code: Select all

If (str != "")  
   str := str "," RowNumber
else    
   str := RowNumber
Oh, that's great. Why didn't I find out so far.
Çok teşekkürler.
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: checkbox status of listview on fly?

12 Oct 2019, 02:31

My previous post was incorrect. It should have been:

Code: Select all

If (str != "")  
   str .= "," RowNumber
else    
   str .= RowNumber
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
User avatar
hasantr
Posts: 780
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: checkbox status of listview on fly?

12 Oct 2019, 03:59

Odlanir wrote:
12 Oct 2019, 02:31
My previous post was incorrect. It should have been:

Code: Select all

If (str != "")  
   str .= "," RowNumber
else    
   str .= RowNumber
Not important. I already understood. And there was the Elvis. :) I learned that too.
Thank you very much.

Return to “Ask For Help”

Who is online

Users browsing this forum: ark, Bing [Bot], mstrauss2021, Xeo786 and 36 guests