Page 1 of 1

Help with ListView & LV_Add

Posted: 12 May 2020, 06:51
by Tomer
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

Re: Help with ListView & LV_Add

Posted: 12 May 2020, 08:27
by boiler

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

Re: Help with ListView & LV_Add

Posted: 12 May 2020, 08:49
by Tomer
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

Re: Help with ListView & LV_Add

Posted: 12 May 2020, 09:03
by boiler
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

Re: Help with ListView & LV_Add

Posted: 12 May 2020, 09:09
by Tomer
Just do both things and name them different variables
I thought there was a short method :)

Thanks !!

Re: Help with ListView & LV_Add  Topic is solved

Posted: 12 May 2020, 13:14
by boiler
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

Re: Help with ListView & LV_Add

Posted: 13 May 2020, 12:13
by Tomer
That's more clearness :)
Thanks

Re: Help with ListView & LV_Add

Posted: 13 May 2020, 15:46
by garry
@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
;========================================================