Jump to content

Checkboxes in ListView


Recommended Posts

I made a listview using the checkboxes for exStyle. As most of you know, it makes checkboxes in front of every item in the listview. How do you determine whether it is checked or not? I tried getting the state of the ListViewItem but it just returns the data thats in it (ie "abc|defg|hijkl").

Thanks in advanced, and thank you to all those who've been helping me! I greatly appriciate all your help!

Link to comment
Share on other sites

Hi,

please show the code, then it is much easier to help you.

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Well, the full code won't do you much good so here is a snippet with spoofed data:

#include <GuiConstants.au3>
#include <GuiListView.au3>
#include <Array.au3>

$version = "1.0"
Dim $pVarName[2], $pVarValue[2], $pVarShared[2], $listViewItems

;SPOOFING ARRAYS - START
$pVarName[0]="variable1"
$pVarName[1]="variable2"
$pVarValue[0]="value1"
$pVarValue[1]="value2"
$pVarShared[0]=0
$pVarShared[1]=0
;SPOOFING ARRAYS - END

GuiCreate("EasyCom " & $version,400,200)
$tab = GUICtrlCreateTab(0,0,399,160)
$tab0 = GUICtrlCreateTabitem("Variables")
$VariableListView = GUICtrlCreateListView("Shared|Variable Name|Value",5,25,390,130,"",$LVS_EX_CHECKBOXES)
_GUICtrlListViewSetColumnWidth($VariableListView,0,46)
_GUICtrlListViewSetColumnWidth($VariableListView,1,90)
_GUICtrlListViewSetColumnWidth($VariableListView,2,230)
GUICtrlCreateTabitem("")

GuiSetState()
_CreateListItems()
While 1
   $msg = GUIGetMsg()
   Select
      Case $msg = $GUI_EVENT_CLOSE
         Exit
   EndSelect
WEnd
GUIDelete()
Exit

Func _CreateListItems()
   _GUICtrlListViewDeleteAllItems($VariableListView)
   If UBound($pVarName) <> UBound($listViewItems) Then
      Dim $listViewItems
      For $i = 0 To UBound($pVarName) - 1
         If $i = 0 Then
            $listViewItems = _ArrayCreate(GUICtrlCreateListViewItem("|" & $pVarName[$i] & "|" & $pVarValue[$i],$VariableListView))
         Else
            _ArrayAdd($listViewItems,GUICtrlCreateListViewItem("|" & $pVarName[$i] & "|" & $pVarValue[$i],$VariableListView))
         EndIf
      Next
   EndIf
EndFunc

Func _UpdateListItems()
   If UBound($pVarName) <> UBound($listViewItems) Then
      _CreateListItems()
      Return
   EndIf
   For $i = 0 To UBound($listViewItems) - 1
      ;If GUICtrlGetState($listViewItems[$i]) = $GUI_CHECKED Then
      MsgBox(0,$i,GUICtrlRead($listViewItems[$i]))
      ;EndIf
      _GUICtrlListViewSetItemText($VariableListView,$i,1,$pVarName[$i])
      _GUICtrlListViewSetItemText($VariableListView,$i,2,$pVarValue[$i])
   Next
EndFunc

This creates ListViewItems with contents like:

"|*VARIABLE1|VALUE1"

The first column is blank because I'm leaving it for the checkbox.

I need to figure out how to get the state of the checkbox.

The array $pVarShared holds either a 1 or a 0. If its a 1 (the checkbox is checked for that item) then 'Shared' is enabled for that item.

Hope you can understand what I'm wanting to do.

@gafrost

I just tried that, it returned 1 everytime even if it wasn't checked.

EDIT: Just kidding gafrost...I was using it wrong. Thanks for the hekp.

Edited by ending
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...