Terenz

Listview checkbox concept

11 posts in this topic

#1 ·  Posted (edited)

Hello,

I have a listview and a list of item-subitem which have the first row-column is always the same.

Pratically i need to "deselect" the first checkbox item and select all the rest, check it out the comment:

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>

Global $MyArray[12]

Global $hGUI = GUICreate("MY_GUI", 300, 300, -1, -1)
Global $iListView = GUICtrlCreateListView("MY_LIST", 8, 9, 200, 200)
GUICtrlSendMsg($iListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, 0, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES, $LVS_EX_DOUBLEBUFFER))

$MyArray[0] = GUICtrlCreateListViewItem("A", $iListView) ; deselect
$MyArray[1] = GUICtrlCreateListViewItem("A", $iListView) ; select
$MyArray[2] = GUICtrlCreateListViewItem("A", $iListView) ; select
$MyArray[3] = GUICtrlCreateListViewItem("A", $iListView) ; select
$MyArray[4] = GUICtrlCreateListViewItem("A", $iListView) ; select
$MyArray[5] = GUICtrlCreateListViewItem("B", $iListView) ; deselect
$MyArray[6] = GUICtrlCreateListViewItem("B", $iListView) ; select
$MyArray[7] = GUICtrlCreateListViewItem("B", $iListView) ; select
$MyArray[8] = GUICtrlCreateListViewItem("C", $iListView) ; deselect
$MyArray[9] = GUICtrlCreateListViewItem("C", $iListView) ; select
$MyArray[10] = GUICtrlCreateListViewItem("C", $iListView) ; select
$MyArray[11] = GUICtrlCreateListViewItem("C", $iListView) ; select

_GUICtrlListView_SetItemChecked($iListView, -1, True) ; by default

; FUNC HERE

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

An image if wasn't clear enought:

r2l4k1.png

Ok i need to loop the array but i don't have idea what is the item to deselect since i don't know the number of item of each "group", the minimun value is 2.

Thanks

Edited by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Share this post


Link to post
Share on other sites



#2 ·  Posted

Terenz,

This works for me:

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>

Global $MyArray[12]

Global $hGUI = GUICreate("MY_GUI", 300, 300, -1, -1)
Global $iListView = GUICtrlCreateListView("MY_LIST", 8, 9, 200, 200)
_GUICtrlListView_SetExtendedListViewStyle($iListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES, $LVS_EX_DOUBLEBUFFER))

$MyArray[0] = GUICtrlCreateListViewItem("A", $iListView) ; deselect
$MyArray[1] = GUICtrlCreateListViewItem("A", $iListView) ; select
$MyArray[2] = GUICtrlCreateListViewItem("A", $iListView) ; select
$MyArray[3] = GUICtrlCreateListViewItem("A", $iListView) ; select
$MyArray[4] = GUICtrlCreateListViewItem("A", $iListView) ; select
$MyArray[5] = GUICtrlCreateListViewItem("B", $iListView) ; deselect
$MyArray[6] = GUICtrlCreateListViewItem("B", $iListView) ; select
$MyArray[7] = GUICtrlCreateListViewItem("B", $iListView) ; select
$MyArray[8] = GUICtrlCreateListViewItem("C", $iListView) ; deselect
$MyArray[9] = GUICtrlCreateListViewItem("C", $iListView) ; select
$MyArray[10] = GUICtrlCreateListViewItem("C", $iListView) ; select
$MyArray[11] = GUICtrlCreateListViewItem("C", $iListView) ; select

$sCurrentText = ""
For $i = 0 To UBound($MyArray) - 1
    If _GUICtrlListView_GetItemText($iListView, $i) = $sCurrentText Then
        _GUICtrlListView_SetItemChecked($iListView, $i, True)
    Else
        $sCurrentText = _GUICtrlListView_GetItemText($iListView, $i)
    EndIf
Next

; FUNC HERE

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

Share this post


Link to post
Share on other sites

#3 ·  Posted

Thanks Melba :D


Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Share this post


Link to post
Share on other sites

#4 ·  Posted

Terenz,

My pleasure, as always.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

19 hours ago, Melba23 said:

M23

Melba don't get mad but my boss has change his idea about the OP :(

Has i have said before i have a listview with of item-subitem. Are a list of names-surname with born date, registration date-time and many other info. For make the things easier for you i have just add 1 column with the autoit format of the date-time so can used with UDF or standard function. My code is different but i'd like just to understand the concept:

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>

Global $MyArray[12]

Global $hGUI = GUICreate("MY_GUI", 300, 300, -1, -1)
Global $iListView = GUICtrlCreateListView("ID|DATE", 8, 9, 200, 200)
GUICtrlSendMsg($iListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, 0, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES, $LVS_EX_DOUBLEBUFFER))

$MyArray[0] = GUICtrlCreateListViewItem("A|1986/10/01 14:10:56", $iListView) ; deselect
$MyArray[1] = GUICtrlCreateListViewItem("A|1984/02/10 16:11:52", $iListView) ; select!!!
$MyArray[2] = GUICtrlCreateListViewItem("A|2007/12/05 10:01:01", $iListView) ; deselect
$MyArray[3] = GUICtrlCreateListViewItem("A|1999/01/14 09:10:57", $iListView) ; deselect
$MyArray[4] = GUICtrlCreateListViewItem("A|2011/01/14 23:11:58", $iListView) ; deselect
$MyArray[5] = GUICtrlCreateListViewItem("B|1985/04/16 18:23:24", $iListView) ; deselect
$MyArray[6] = GUICtrlCreateListViewItem("B|1980/02/10 16:11:52", $iListView) ; select!!!
$MyArray[7] = GUICtrlCreateListViewItem("B|1980/02/10 16:11:52", $iListView) ; deselect
$MyArray[8] = GUICtrlCreateListViewItem("C|1995/07/19 22:11:47", $iListView) ; deselect
$MyArray[9] = GUICtrlCreateListViewItem("C|1979/12/15 05:11:25", $iListView) ; select!!!
$MyArray[10] = GUICtrlCreateListViewItem("C|2001/05/22 20:10:57", $iListView) ; deselect
$MyArray[11] = GUICtrlCreateListViewItem("C|1979/12/15 09:10:57", $iListView) ; deselect

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

I need to select the ID of the group with the older born date, like before always 1 for group

Group A is easy, take the older man

In the group B there is an (impossible, but just for be sure) situation with the same born date and registration time, in that case select the first of the two

In the group C there is two man with the same born date but different registration time, take the one who was recorded before

Anyway there are comments if i wasn't clear

Sorry

Edited by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Share this post


Link to post
Share on other sites

#6 ·  Posted

Terenz,

Quote

don't get mad

Of course not - bosses are like that!

I suggest putting the original data into an array and then sorting it using my ArrayMultiColSort to get it in the required order. Once this is done you can still use the same algorithm as above to check the later elements:

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>

#include "ArrayMultiColSort.au3"

Global $MyArray[12]

Global $MyData[12][3] = [["A", "1986/10/01 14:10:56"], _
                         ["A", "1984/02/10 16:11:52"], _
                         ["A", "2007/12/05 10:01:01"], _
                         ["A", "1999/01/14 09:10:57"], _
                         ["A", "2011/01/14 23:11:58"], _
                         ["B", "1985/04/16 18:23:24"], _
                         ["B", "1980/02/10 16:11:52"], _
                         ["B", "1980/02/10 16:11:52"], _
                         ["C", "1995/07/19 22:11:47"], _
                         ["C", "1979/12/15 05:11:25"], _
                         ["C", "2001/05/22 20:10:57"], _
                         ["C", "1979/12/15 09:10:57"]]

; Sort columns in the order 0-1-2 in ascending order
Global $aSortData[][] = [[0, 0], _
                         [1, 0], _
                         [2, 0]]
_ArrayMultiColSort($MyData, $aSortData)

Global $hGUI = GUICreate("MY_GUI", 300, 300, -1, -1)
Global $iListView = GUICtrlCreateListView("ID|DATE", 8, 9, 200, 200)
GUICtrlSendMsg($iListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, 0, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES, $LVS_EX_DOUBLEBUFFER))

For $i = 0 To UBound($MyArray) - 1
    $MyArray[$i] = GUICtrlCreateListViewItem($MyData[$i][0] & "|" & $MyData[$i][1] & "|" & $MyData[$i][2], $iListView)
Next
$sCurrentText = ""
For $i = 0 To UBound($MyArray) - 1
    If _GUICtrlListView_GetItemText($iListView, $i) = $sCurrentText Then
        _GUICtrlListView_SetItemChecked($iListView, $i, True)
    Else
        $sCurrentText = _GUICtrlListView_GetItemText($iListView, $i)
    EndIf
Next

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

You can find the UDF link in my sig.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

Share this post


Link to post
Share on other sites

#7 ·  Posted

3 hours ago, Melba23 said:

M23

Melba i'm not sure i can change the sorting order, i'll ask but is more "no" then "yes"

Is possible to do without alter the original sort? Some magic loop? :D


Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Share this post


Link to post
Share on other sites

#8 ·  Posted

Terenz,

If you use another of my UDFs (GUIListViewEx) to extract the ListView content once written you could always do something like this:

#include <GUIConstantsEx.au3>
#include <Array.au3>

#include <GuiListViewEx.au3>
#include "ArrayMultiColSort.au3"

Global $MyArray[12]

Global $hGUI = GUICreate("MY_GUI", 300, 300, -1, -1)
Global $iListView = GUICtrlCreateListView("ID|DATE", 8, 9, 200, 200)
GUICtrlSendMsg($iListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, 0, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES, $LVS_EX_DOUBLEBUFFER))

$MyArray[0] = GUICtrlCreateListViewItem("A|1986/10/01 14:10:56", $iListView) ; deselect
$MyArray[1] = GUICtrlCreateListViewItem("A|1984/02/10 16:11:52", $iListView) ; select!!!
$MyArray[2] = GUICtrlCreateListViewItem("A|2007/12/05 10:01:01", $iListView) ; deselect
$MyArray[3] = GUICtrlCreateListViewItem("A|1999/01/14 09:10:57", $iListView) ; deselect
$MyArray[4] = GUICtrlCreateListViewItem("A|2011/01/14 23:11:58", $iListView) ; deselect
$MyArray[5] = GUICtrlCreateListViewItem("B|1985/04/16 18:23:24", $iListView) ; deselect
$MyArray[6] = GUICtrlCreateListViewItem("B|1980/02/10 16:11:52", $iListView) ; select!!!
$MyArray[7] = GUICtrlCreateListViewItem("B|1980/02/10 16:11:52", $iListView) ; deselect
$MyArray[8] = GUICtrlCreateListViewItem("C|1995/07/19 22:11:47", $iListView) ; deselect
$MyArray[9] = GUICtrlCreateListViewItem("C|1979/12/15 05:11:25", $iListView) ; select!!!
$MyArray[10] = GUICtrlCreateListViewItem("C|2001/05/22 20:10:57", $iListView) ; deselect
$MyArray[11] = GUICtrlCreateListViewItem("C|1979/12/15 09:10:57", $iListView) ; deselect

; get the ListView content into ann array
$aLVArray = _GUIListViewEx_ReadToArray($iListView)
; Add 2 more columns
_ArrayColInsert($aLVArray, 2)
_ArrayColInsert($aLVArray, 3)
; Split the date/time and add the original index of the item
For $i = 0 To UBound($aLVArray) - 1
    $aSplit = StringSplit($aLVArray[$i][1], " ")
    $aLVArray[$i][1] = $aSplit[1]
    $aLVArray[$i][2] = $aSplit[2]
    $aLVArray[$i][3] = $i
Next
; Sort columns in the order 0-1-2 in ascending order
Global $aSortData[][] = [[0, 0], _
                         [1, 0], _
                         [2, 0]]
_ArrayMultiColSort($aLVArray, $aSortData)
; Now find the lead item for each section 
$sCurrText = ""
For $i = 0 To UBound($aLVArray) - 1
    If $aLVArray[$i][0] = $sCurrText Then
        ; Not a lead item, so check - the original index is stored within the array
         _GUICtrlListView_SetItemChecked($iListView, $aLVArray[$i][3], True)
    Else
        $sCurrText = $aLVArray[$i][0]
    EndIf
Next

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Any use?

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

Share this post


Link to post
Share on other sites

#9 ·  Posted

17 minutes ago, Melba23 said:

M23

I'll check it out thanks. A question about your _ArrayMultiColSort. Assuming i have 7 columns ( 0-1-2-3-4-5-6 ) and i want to sort for column 1 and then 5 i need to write in this way?

Local $aSortData[2][2] = [[1, 0],[5, 0]]

 


Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Share this post


Link to post
Share on other sites

#10 ·  Posted

Terenz,

That syntax should do what you want.

Why do I get the impression that this whole matter is very much more complex than you are currently admitting?

M23

 


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

Share this post


Link to post
Share on other sites

#11 ·  Posted

I'll admit, is complex. But the listview to manage, the information and all the related stuff. Your script is a good point to start.


Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Share this post


Link to post
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