Checked ListView element if write it name in the GUI Edit Control Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
HiSoKa
Posts: 480
Joined: 27 Jan 2020, 15:43

Checked ListView element if write it name in the GUI Edit Control

Post by HiSoKa » 07 Dec 2022, 15:51

I have this code,
How can I make a Checked for the element whose name is written in the edit control

Code: Select all

Gui, Add, ListView, W300 H300 Checked, Column
    Loop, 30
        LV_Add(, "Row " . A_Index)
Gui, add, edit , vSearchTerm w300 h50
	Gui, Show
Return

Enter::
GuiControlGet, SearchTerm
MsgBox, % SearchTerm
Return

esc::ExitApp
And how i can get it row number...
Thanks in advance for the time

User avatar
flyingDman
Posts: 2791
Joined: 29 Sep 2013, 19:01

Re: Checked ListView element if write it name in the GUI Edit Control  Topic is solved

Post by flyingDman » 07 Dec 2022, 16:28

Loop through the ListView and use LV_getText.

Code: Select all

Gui, Add, ListView, W300 H300 Checked, Column
Loop, 30
	LV_Add(, "Row " . A_Index)
Gui, add, edit , vSearchTerm w300
Gui, Show
Return

Enter::
GuiControlGet, SearchTerm
loop, % LV_Getcount()
	{
	lv_gettext(oVar,a_index)
	if (ovar = searchterm)
		{
		msgbox Row Number = %a_index%
		lv_modify(a_index, "check")
		}
	}
Return

esc::ExitApp
BTW I would not use Enter
14.3 & 1.3.7

User avatar
HiSoKa
Posts: 480
Joined: 27 Jan 2020, 15:43

Re: Checked ListView element if write it name in the GUI Edit Control

Post by HiSoKa » 07 Dec 2022, 16:44

Thank you so much, this is what I was looking for :)

User avatar
HiSoKa
Posts: 480
Joined: 27 Jan 2020, 15:43

Re: Checked ListView element if write it name in the GUI Edit Control

Post by HiSoKa » 08 Dec 2022, 01:46

Hi @flyingDman How i can make like toggle for that lv_modify(a_index, "check")
I mean if element check should i get lv_modify(a_index, "-check") otherwise lv_modify(a_index, "check")

Maybe Ternary operator it will help, but sorry im not good in it :(

User avatar
flyingDman
Posts: 2791
Joined: 29 Sep 2013, 19:01

Re: Checked ListView element if write it name in the GUI Edit Control

Post by flyingDman » 08 Dec 2022, 07:39

Try:

Code: Select all

Gui, Add, ListView, W300 H300 Checked, Column
Loop, 30
	LV_Add(, "Row " . A_Index)
Gui, add, edit , vSearchTerm w300
Gui, Show
Return

^Enter::
GuiControlGet, SearchTerm
loop, % LV_Getcount()
	{
	lv_gettext(oVar,a_index)
	if (ovar = searchterm)
		{
		msgbox Row Number = %a_index%
		if (LV_GetNext(a_index -1, "checked"))
			lv_modify(a_index, "-check")
		else
			lv_modify(a_index, "check")
		}
	}
Return

esc::ExitApp
14.3 & 1.3.7

User avatar
HiSoKa
Posts: 480
Joined: 27 Jan 2020, 15:43

Re: Checked ListView element if write it name in the GUI Edit Control

Post by HiSoKa » 08 Dec 2022, 08:12

The code does not respond If there are checked element after target row.

User avatar
flyingDman
Posts: 2791
Joined: 29 Sep 2013, 19:01

Re: Checked ListView element if write it name in the GUI Edit Control

Post by flyingDman » 08 Dec 2022, 10:40

Try this instead:

Code: Select all

Gui, Add, ListView, W300 H300 Checked, Column
Loop, 30
	LV_Add(, "Row " . A_Index)
Gui, add, edit , vSearchTerm w300
Gui, Show
Return

^Enter::
GuiControlGet, SearchTerm
loop, % LV_Getcount()
	{
	lv_gettext(oVar,a_index)
	if (ovar = searchterm)
		{
		msgbox Row Number = %a_index%
		Gui +LastFound
		SendMessage, 0x102C, a_index - 1, 0xF000, SysListView321
		if (ErrorLevel >> 12) - 1
			lv_modify(a_index, "-check")
		else
			lv_modify(a_index, "check")
		}
	}
Return
or with the ternary:

Code: Select all

Gui, Add, ListView, W300 H300 Checked, Column
Loop, 30
	LV_Add(, "Row " . A_Index)
Gui, add, edit , vSearchTerm w300
Gui, Show
Return

^Enter::
GuiControlGet, SearchTerm
loop, % LV_Getcount()
	{
	lv_gettext(oVar,a_index)
	if (ovar = searchterm)
		{
		msgbox Row Number = %a_index%
		Gui +LastFound
		SendMessage, 0x102C, a_index - 1, 0xF000, SysListView321
		lv_modify(a_index, (ErrorLevel >> 12) - 1 ? "-check" : "check")
		}
	}
Return
14.3 & 1.3.7

User avatar
HiSoKa
Posts: 480
Joined: 27 Jan 2020, 15:43

Re: Checked ListView element if write it name in the GUI Edit Control

Post by HiSoKa » 08 Dec 2022, 10:45

Everything is working fine now :thumbup: , much appreciated..

Post Reply

Return to “Ask for Help (v1)”