Sign in to follow this  
Followers 0
SumTingWong

ListViewItem oddities

9 posts in this topic

#1 ·  Posted (edited)

Could someone run this code in beta 87 and confirm the results I am getting?

ListView is multi-select so select a few items before clicking on Test.

#include <GUIConstants.au3>

Dim $lviTestItems[10]

GUICreate("MyGUI", 200, 400)
$lvTest = GUICtrlCreateListView("Header1", 20, 20, 160, 320, BitOR($LVS_SHOWSELALWAYS, $LVS_REPORT))
For $i = 0 To 9
$lviTestItems[$i] = GUICtrlCreateListViewItem("Test " & $i, $lvTest)
Next
$btnTest = GUICtrlCreateButton("Test", 20, 360, 80, 25)
GUISetState(@SW_SHOW)
While 1
    $msg = GUIGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $btnTest
  For $i = 0 To 9
   $aItem = GUICtrlRead($lviTestItems[$i], 1)
   ConsoleWrite($aItem[0] & "," & $aItem[1] & @LF)
  Next
    EndSelect
WEnd
GUIDelete()

This is what I am getting:

Test 0,-1
Test 1,-1
Test 2,-1
Test 3,-1
Test 4,-1
Test 5,-1
Test 6,-1
Test 7,-1
Test 8,-1
Test 9,-1

According to the help file:

In 'advanced' mode the return value is a two-dimensional array.

The second element of this value contains the same value like given in the default-table.

The first element contains additional data of the control (see below).

From the results I am getting, 2 things are wrong.

Firstly, ListViewItem needs to be added to the default table as follows:

ListViewItem State of the ListViewItem

Also, change the ListViewItem entry in the Remarks section to say The text of the ListViewItem

Second, the state value is always -1 regardless of whether the item is selected or not.

Edited by SumTingWong

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

From the results I am getting, 2 things are wrong.

Firstly, ListViewItem needs to be added to the default table as follows:

Also, change the ListViewItem entry in the Remarks section to say The text of the ListViewItemThat's correct. GUICtrlRead() when applied to a ListView Item:

Normal mode - returns the text of ListView Item

Advanced Mode - two dimensional array: Array[0] = Text of ListView Item, Array[1] = State of ListView Item.

Second, the state value is always -1 regardless of whether the item is selected or not.

The state table dosen't have any state value for Selected/Unselected

State Comments

No Change 0

$GUI_UNCHECKED Radio or Checkbox will be unchecked

$GUI_CHECKED Radio or Checkbox will be checked

$GUI_INDETERMINATE Checkbox having the tristate attribute will be greyed

$GUI_AVISTART Avi control will start playing

$GUI_AVISTOP Avi control will stop playing

$GUI_AVICLOSE Avi control will stop playing and release resource

$GUI_ACCEPTFILES Input or Edit control will accept drag and drop of files

$GUI_SHOW Control will be visible. On Tabitem control will select the first tab to be displayed

$GUI_HIDE Control will not be visible

$GUI_ENABLE Control will be enabled

$GUI_DISABLE Control will be greyed out

$GUI_FOCUS Control will be given input/selected focus

$GUI_DEFBUTTON Control will be set as the default button on the window

$GUI_EXPAND TreeViewItem will expand it's child items.

To know which items user has selected/unselected, an alternate methord is to use $LVS_EX_CHECKBOXES extended list view style.

You can change the GuiCtrlCreateListView line in your script to:

$lvTest = GUICtrlCreateListView("Header1", 20, 20, 160, 320, BitOR($LVS_SHOWSELALWAYS, $LVS_REPORT), $LVS_EX_CHECKBOXES)

and the script output would be:

Test 0,4

Test 1,4

Test 2,1

Test 3,4

Test 4,1

Test 5,4

Test 6,1

Test 7,4

Test 8,4

Test 9,4

In this test run I checked items 2, 4 and 6

4 means items is unchecked = $GUI_UNCHECKED

1 means item is checked = $GUI_CHECKED

Edited by tonedeaf

Share this post


Link to post
Share on other sites

@tonedeaf

Perfect diagnosis.

I don't know why Holger introduce this state which is irrelevant when you do not use $LVS_EX_CHECKBOXES

The doc is a little missleading on this subject B)

Share this post


Link to post
Share on other sites

Yeah, I see.

What about these return values:

0 - item is unselected

$GUI_FOCUS : item is selected

$GUI_CHECKED : item is checked (with LVS_EX_CHECKBOXES-style)

$GUI_CHECKED + $GUI_FOCUS : item is checked and selected

$GUI_UNCHECKED : item is unchecked

$GUI_UNCHECKED + $GUI_FOCUS : item is unchecked and selected

What do you think?

So long B)

Holger

Share this post


Link to post
Share on other sites

Yeah, I see.

What about these return values:

0 - item is unselected

$GUI_FOCUS : item is selected

$GUI_CHECKED : item is checked (with LVS_EX_CHECKBOXES-style)

$GUI_CHECKED + $GUI_FOCUS : item is checked and selected

$GUI_UNCHECKED : item is unchecked

$GUI_UNCHECKED + $GUI_FOCUS : item is unchecked and selected

What do you think?

So long B)

Holger

Makes sense to me.

At the moment, without resorting to using checkboxes as suggested, I am having to use ControlListView to enumerate selected items.

Share this post


Link to post
Share on other sites

Yeah, I see.

What about these return values:

0 - item is unselected

$GUI_FOCUS : item is selected

$GUI_CHECKED : item is checked (with LVS_EX_CHECKBOXES-style)

$GUI_CHECKED + $GUI_FOCUS : item is checked and selected

$GUI_UNCHECKED : item is unchecked

$GUI_UNCHECKED + $GUI_FOCUS : item is unchecked and selected

What do you think?

So long B)

Holger

I prefer to introduce $GUI_SELECTED not to confuse with real focus in case of for the future

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

@jpm: good idea B)

so we have then the following states:

0 - No change

$GUI_FOCUS : item is selected and listview parent windows gets focus

$GUI_SELECTED : item is selected

$GUI_CHECKED : item is checked

$GUI_UNCHECKED : item is unchecked

So the state could be a combination of these values.

I also will add/change this for the treeview control, for the tab items I will see.

So long....

Edited by Holger

Share this post


Link to post
Share on other sites

@jpm: good idea :)

so we have then the following states:

0 - No change

$GUI_FOCUS : item is selected and listview parent windows gets focus

$GUI_SELECTED : item is selected

$GUI_CHECKED : item is checked

$GUI_UNCHECKED : item is unchecked

So the state could be a combination of these values.

I also will add/change this for the treeview control, for the tab items I will see.

So long....


Phillip

Share this post


Link to post
Share on other sites

@jpm: good idea :)

so we have then the following states:

0 - No change

$GUI_FOCUS : item is selected and listview parent windows gets focus

$GUI_SELECTED : item is selected

$GUI_CHECKED : item is checked

$GUI_UNCHECKED : item is unchecked

So the state could be a combination of these values.

I also will add/change this for the treeview control, for the tab items I will see.

So long....

What happened to $GUI_SELECTED?&nbsp; I do not see it in GuiConstants.Au3 or a value returned for it when a List View Item is selected.&nbsp; A forum search for $GUI_SELECTED returns only this thread.

Phillip

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
Sign in to follow this  
Followers 0