Jump to content

Listview checkbox sorting cannot get the right result


Recommended Posts

Hi All, 

I'm trying to sort a Listview with checkboxes...looks likes it works fine.. everything looks sorted

But i have a little problem which i cannot solve (I believe i am the problem :sweating: )

If you run the code below and follow the steps

- Select the fourth checkbox and press "Show checked" button  it will display the right result in a messagebox.

- Sort by pressing field C and you will see the checkbox moves to the first position, still correct

- Press the button "Show checked" and it displays the information which was before the sorting on the first position.. this is correct because the code isn't correct..how can i read the content of the line which is checked instead of the wrong line or just one column.

Or is the only solution to read all the column if you want the complete line ?!!!

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

Dim $sListViewItem[500]

GUICreate("Sorting with CheckBoxes", 400, 480)
$sListView = GUICtrlCreateListView("Select|A|B|C|D|E", 20, 20, 360, 400)
_GUICtrlListView_SetExtendedListViewStyle($sListview, $LVS_EX_CHECKBOXES)


_GUICtrlListView_SetColumnWidth($sListView, 0, 60)
_GUICtrlListView_SetColumnWidth($sListView, 1, 60)
_GUICtrlListView_SetColumnWidth($sListView, 2, 60)
_GUICtrlListView_SetColumnWidth($sListView, 3, 60)
_GUICtrlListView_SetColumnWidth($sListView, 4, 60)
_GUICtrlListView_SetColumnWidth($sListView, 5, 60)



$sListviewItem[0] = GUICtrlCreateListViewItem("|111|222|333|444|555", $sListView)
$sListviewItem[1] = GUICtrlCreateListViewItem("|222|333|444|555|111", $sListView)
$sListviewItem[2] = GUICtrlCreateListViewItem("|333|444|555|111|222", $sListView)
$sListviewItem[3] = GUICtrlCreateListViewItem("|444|555|111|222|333", $sListView)
$sListviewItem[4] = GUICtrlCreateListViewItem("|555|111|222|333|444", $sListView)

$sButton = GUICtrlCreateButton("Show checked", 280, 440, 100,20)

GUISetState ()

_GUICtrlListView_RegisterSortCallBack($sListView)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            _GUICtrlListView_UnRegisterSortCallBack($sListView)
            Exit
        Case $msg = $sButton
            For $i = 0 to 4
                If _GUICtrlListView_GetItemChecked($sListView, $i) = "true" Then
                    ; the following is off course the problem because it reads the incorrect row
                    msgbox (64, "Checked value", GUICtrlRead($sListViewItem[$i]))
                    ; the following only checks one column, how to retrieve the whole line
                                        msgbox (64, "Checked value", _GUICtrlListView_GetItemText($sListView, $i, 1))
                EndIf
            Next
        Case $msg = $sListView
            _GUICtrlListView_SortItems($sListView, GUICtrlGetState($sListView))
    EndSelect
Wend
Edited by Emiel Wieldraaijer

Best regards,Emiel Wieldraaijer

Link to comment
Share on other sites

?

Case $msg = $sButton
            For $i = 0 to 4
                If _GUICtrlListView_GetItemChecked($sListView, $i) = "true" Then
                    $txt = _GUICtrlListView_GetItemTextString($sListView, $i)
                    Msgbox(0,"", $txt)
                   ; $array = _GUICtrlListView_GetItemTextArray($sListView, $i)
                   ; _ArrayDisplay($array)
                EndIf
            Next
Edited by mikell
Link to comment
Share on other sites

for Best coding practices when you check If _GUICtrlListView_GetItemChecked($sListView, $i) = "true" Then. Use a bool value. not a string "true"

Saludos

Link to comment
Share on other sites

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...