Page 1 of 1

A problem of uncheck all checkboxes of a listview

Posted: 11 May 2024, 02:52
by songdg
I want to uncheck all checkboxes of a listview by doubleclick on the text Uncheck_All, but get this error
Error: This value of type "Gui.Text" has no method named "Modify".

011: g.OnEvent("Close", (*) => ExitApp())
014: {
▶ 015: LV.Modify(0, "-Check")
016: }
020: {

Code: Select all

#Requires AutoHotkey v2.0
g := Gui("+AlwaysOnTop")
g.Add("Text", "VUncheck cRed", "Uncheck_All").OnEvent('doubleclick', Uncheck_All)
LV := g.AddListView("w400 r12 -readonly checked", ["name","items"])
loop 12
	LV.Add(, "Name " A_Index,"Item " A_Index * 10)
LV.modifycol(1, 190)
LV.modifycol(2, 190)
LV.OnEvent("doubleclick", LVClick)
g.Show()
g.OnEvent("Close", (*) => ExitApp())

Uncheck_All(LV, Item,*)
{
  LV.Modify(0, "-Check")  ; Uncheck all the checkboxes.
}

LVClick(LV, Item,*)
{
  {
  ItemState := SendMessage(0x102C, item - 1, 0xF000, LV)
  if !((ItemState >> 12) - 1)
      LV.Modify(item,	"Check")
  else
      LV.Modify(item,	"-Check")
  }
}

Re: A problem of uncheck all checkboxes of a listview

Posted: 11 May 2024, 03:13
by vmech
@songdg
Because Uncheck_All callback take Text Gui Control object in named LV parameter. Not ListView Gui Control object.
Try:

Code: Select all

Uncheck_All(*)
{
  global LV
  LV.Modify(0, "-Check")  ; Uncheck all the checkboxes.
}
Spoiler

Re: A problem of uncheck all checkboxes of a listview  Topic is solved

Posted: 11 May 2024, 04:37
by XMCQCX
As stated by @vmech, the LV parameter represents the text Gui Control object, not the ListView Gui Control object. I highly recommend using VSCode alongside the Debugger extension. By hovering over variables, you can examine both their type and content. You will save a ton of time.
Image

Code: Select all

#Requires AutoHotkey v2.0
#SingleInstance

g := Gui('+AlwaysOnTop')
g.OnEvent('Close', (*) => ExitApp())
g.Add('Text',, 'Check all').OnEvent('DoubleClick', (*) => g.lv.Modify(0, '+Check'))
g.Add('Text', 'x+m', 'Uncheck all').OnEvent('DoubleClick', (*) => g.lv.Modify(0, '-Check'))
g.Add('Text', 'x+m', 'Select all').OnEvent('DoubleClick', (*) => g.lv.Modify(0, '+Select'))
g.Add('Text', 'x+m', 'Deselect all').OnEvent('DoubleClick', (*) => g.lv.Modify(0, '-Select'))
g.lv := g.AddListView('xm w400 r12 -readonly checked', ['name','items'])

loop 12
    g.lv.Add(, 'Name ' A_Index,'Item ' A_Index * 10)

Loop 2
    g.lv.modifycol(A_Index, 190)

g.Show()

Re: A problem of uncheck all checkboxes of a listview

Posted: 12 May 2024, 11:41
by songdg
vmech wrote:
11 May 2024, 03:13
@songdg
Because Uncheck_All callback take Text Gui Control object in named LV parameter. Not ListView Gui Control object.
Try:

Code: Select all

Uncheck_All(*)
{
  global LV
  LV.Modify(0, "-Check")  ; Uncheck all the checkboxes.
}
Spoiler
Thank you very much :clap:

Re: A problem of uncheck all checkboxes of a listview

Posted: 12 May 2024, 11:43
by songdg
XMCQCX wrote:
11 May 2024, 04:37
As stated by @vmech, the LV parameter represents the text Gui Control object, not the ListView Gui Control object. I highly recommend using VSCode alongside the Debugger extension. By hovering over variables, you can examine both their type and content. You will save a ton of time.
Image

Code: Select all

#Requires AutoHotkey v2.0
#SingleInstance

g := Gui('+AlwaysOnTop')
g.OnEvent('Close', (*) => ExitApp())
g.Add('Text',, 'Check all').OnEvent('DoubleClick', (*) => g.lv.Modify(0, '+Check'))
g.Add('Text', 'x+m', 'Uncheck all').OnEvent('DoubleClick', (*) => g.lv.Modify(0, '-Check'))
g.Add('Text', 'x+m', 'Select all').OnEvent('DoubleClick', (*) => g.lv.Modify(0, '+Select'))
g.Add('Text', 'x+m', 'Deselect all').OnEvent('DoubleClick', (*) => g.lv.Modify(0, '-Select'))
g.lv := g.AddListView('xm w400 r12 -readonly checked', ['name','items'])

loop 12
    g.lv.Add(, 'Name ' A_Index,'Item ' A_Index * 10)

Loop 2
    g.lv.modifycol(A_Index, 190)

g.Show()
Thanks for the help and recommendation :dance: