Help with ListView & LV_Add Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
User avatar
Tomer
Posts: 314
Joined: 21 Aug 2016, 05:11

Help with ListView & LV_Add

12 May 2020, 06:51

code below showing the checkboxs selected from the the listview,
im want to show the unselected checkboxs instead.

thanks in advance!

Code: Select all

ListProfile := " C:\ | D:\ | E:\"

Gui, Add, ListView, Checked Grid, list
For each, file in % StrSplit(RTrim(ListProfile, "|"), "|")
    LV_Add("check",substr(file,1))
Gui Add, Button,gOK, OK
Gui, Show
return

OK:
 namelist =
 name := 0
 Row := 0
 names := Object()
 Loop {
   Row := LV_GetNext(Row, "C")
   If (!Row) 
      Break
   LV_GetText(name, Row, 1)
   names.Insert(name)
   namelist .= name "`n"  
 }
 
 MsgBox % namelist
User avatar
boiler
Posts: 5557
Joined: 21 Dec 2014, 02:44

Re: Help with ListView & LV_Add

12 May 2020, 08:27

Code: Select all

ListProfile := " C:\ | D:\ | E:\"

Gui, Add, ListView, Checked Grid, list
For each, file in % StrSplit(RTrim(ListProfile, "|"), "|")
    LV_Add("check",substr(file,1))
Gui Add, Button,gOK, OK
Gui, Show
return

OK:
 namelist =
 name := 0
 names := Object()
 Loop % LV_GetCount() {
   Row := LV_GetNext(A_Index - 1, "C")
   if (Row != A_Index) {
      LV_GetText(name, A_Index, 1)
      names.Insert(name)
      namelist .= name "`n"  
   }
 }
 
 MsgBox % namelist
return
User avatar
Tomer
Posts: 314
Joined: 21 Aug 2016, 05:11

Re: Help with ListView & LV_Add

12 May 2020, 08:49

Thanks boiler it wotks but i still want to keep the ability to have the selected items aswell with name,
and namelist will return the unselected items

If it can be combined together it would be great

Code: Select all

ListProfile := " C:\ | D:\ | E:\"

Gui, Add, ListView, Checked Grid, list
For each, file in % StrSplit(RTrim(ListProfile, "|"), "|")
    LV_Add("check",substr(file,1))
Gui Add, Button,gOK, OK
Gui, Show
return

OK:
 namelist =
 name := 0
 Row := 0
 names := Object()
 Loop {
   Row := LV_GetNext(Row, "C")
   If (!Row) 
      Break
   LV_GetText(name, Row, 1)
   names.Insert(name)
   namelist .= name "`n"  
   
 }
 

For i, name in names
  MsgBox % name
User avatar
boiler
Posts: 5557
Joined: 21 Dec 2014, 02:44

Re: Help with ListView & LV_Add

12 May 2020, 09:03

Just do both things and name them different variables:

Code: Select all

ListProfile := " C:\ | D:\ | E:\"

Gui, Add, ListView, Checked Grid, list
For each, file in % StrSplit(RTrim(ListProfile, "|"), "|")
    LV_Add("check",substr(file,1))
Gui Add, Button,gOK, OK
Gui, Show
return

OK:
 namelist =
 name := 0
 Row := 0
 names := Object()
 Loop {
   Row := LV_GetNext(Row, "C")
   If (!Row) 
      Break
   LV_GetText(name, Row, 1)
   names.Insert(name)
   namelist .= name "`n"  
   
 }
 

 namelistUnch =
 name := 0
 namesUnch := Object()
 Loop % LV_GetCount() {
   Row := LV_GetNext(A_Index - 1, "C")
   if (Row != A_Index) {
      LV_GetText(name, A_Index, 1)
      namesUnch.Insert(name)
      namelistUnch .= name "`n"  
   }
 }


For i, name in names
  MsgBox % "checked: "name

For i, name in namesUnch
  MsgBox, % "unchecked: " name

return

Esc::ExitApp
User avatar
Tomer
Posts: 314
Joined: 21 Aug 2016, 05:11

Re: Help with ListView & LV_Add

12 May 2020, 09:09

Just do both things and name them different variables
I thought there was a short method :)

Thanks !!
User avatar
boiler
Posts: 5557
Joined: 21 Dec 2014, 02:44

Re: Help with ListView & LV_Add  Topic is solved

12 May 2020, 13:14

Well, that's a good point. It is more efficient to combine the two loops into one:

Code: Select all

ListProfile := " C:\ | D:\ | E:\"

Gui, Add, ListView, Checked Grid, list
For each, file in % StrSplit(RTrim(ListProfile, "|"), "|")
    LV_Add("check",substr(file,1))
Gui Add, Button,gOK, OK
Gui, Show
return

OK:
 namelist =
 namelistUnch =
 name := 0
 Row := 0
 names := Object()
 namesUnch := Object()
 Loop % LV_GetCount() {
   Row := LV_GetNext(A_Index - 1, "C")
   if (Row = A_Index) {
   LV_GetText(name, Row, 1)
   names.Insert(name)
   namelist .= name "`n"  
   } else {
      LV_GetText(name, A_Index, 1)
      namesUnch.Insert(name)
      namelistUnch .= name "`n"  
   }
 }


For i, name in names
  MsgBox % "checked: "name

For i, name in namesUnch
  MsgBox, % "unchecked: " name

return

Esc::ExitApp
User avatar
Tomer
Posts: 314
Joined: 21 Aug 2016, 05:11

Re: Help with ListView & LV_Add

13 May 2020, 12:13

That's more clearness :)
Thanks
garry
Posts: 2331
Joined: 22 Dec 2013, 12:50

Re: Help with ListView & LV_Add

13 May 2020, 15:46

@boiler , thank you
a basic example with files

Code: Select all

#warn
#Noenv
setworkingdir,%a_scriptdir%
Gui,2: Default
Gui,2: +LastFound
Gui,2: Font,s12 CDefault,Lucida Console
Gui,2: Add, ListView, W600 H500 Checked Grid altsubmit vLV1 gListLabel , NR|Filename|Size
i=0
Loop, %A_MyDocuments%\*.*,0,1
  {
  i++
  i:=SubStr(00 i, -2)
  LV_Add("",i, A_LoopFileName, A_LoopFileSize)
  }
  LV_ModifyCol(1,60),  LV_ModifyCol(2,300), LV_ModifyCol(3,100),  LV_ModifyCol(3,"integer")

Gui,2: Add, Button, gSelectall  , SelectAll
Gui,2: Add, Button, gDeselectall, CancelSelected
Gui,2: Add, Button, gGetChecked , Show Selected
Gui,2: show
return
;--------------------------------------
2GUIClose:
2GUIEscape:
ExitApp

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

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

ListLabel:
  Gui,2: Submit, NoHide
  Gui,2:ListView, LV1
      RN:=LV_GetNext("C")
      RF:=LV_GetNext("F")
      GC:=LV_GetCount()

  If A_GuiEvent = Doubleclick
      {
      LV_GetText(C1,A_EventInfo,1)
      LV_GetText(C2,A_EventInfo,2)
      LV_GetText(C3,A_EventInfo,3)
      msgbox, 262208, Info, Filename=%c2%`nSize=%c3%
      }
return
;----------------------------------------------------

GetChecked:
i1=0
i2=0
t1:=""
t2:=""
checkedrows:=""
Loop ,%GC%
{
Row := LV_GetNext(A_Index - 1, "C")
if (Row = A_Index) 
  {
  i1++
  CheckedRows .= CheckedRows ? "," Row : Row
  LV_GetText(C2, Row, 2)
  t1 .= c2 . "`n"
  }
else
  {
  i2++
  LV_GetText(C2, A_Index, 2)
  t2 .= c2 . "`n"
  }
}
a= Total=%gc%`nCheckedrows=`n%checkedrows%`n--------------`nTotal checked=%i1%`n%t1%`n---------------`nTotal NOT checked=%i2%`n%t2%
msgbox, 262208, Info,%a%
return
;========================================================

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], CarPiotr, TAC109 and 57 guests