Jump to content

[Solved] Strange results with listviews


Recommended Posts

While console gives the wanted output Listview is not correct whatever I tried.

See example 2

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>

$Form1 = GUICreate("Example 1", 800, 600, -1, -1)
$hListView = GUICtrlCreateListView("", 12, 12, 500, 500)
; Add columns
_GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 200)
_GUICtrlListView_InsertColumn($hListView, 1, "Column 2", 100)

For $i = 1 To 10
_GUICtrlListView_AddItem($hListView, $i)
    For $ii = 1 To 10
        _GUICtrlListView_AddItem($hListView, $ii)
        ConsoleWrite($i & @TAB & $ii & @CRLF)
    Next
    Next
GUISetState(@SW_SHOW)
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            GUIDelete()
            ExitLoop
    EndSwitch
    Sleep(10)
WEnd

$Form2 = GUICreate("Example 2", 800, 600, -1, -1)
$hListView = GUICtrlCreateListView("", 12, 12, 500, 500)
; Add columns
_GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 200)
_GUICtrlListView_InsertColumn($hListView, 1, "Column 2", 100)

_GUICtrlListView_EnableGroupView($hListView)
For $i = 1 To 10
    _GUICtrlListView_InsertGroup($hListView, -1, $i, $i)
    For $ii = 1 To 10
        _GUICtrlListView_AddItem($hListView, $ii)
        _GUICtrlListView_SetItemGroupID($hListView, $i - 1, $i)
        ConsoleWrite($i & @TAB & $ii & @CRLF)
    Next
Next
GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    Sleep(10)
WEnd
Edited by Fantastic
Link to comment
Share on other sites

Fantastic,

You had some minor errors in your logic. See the correct example:

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>

$Form1 = GUICreate("Example 1", 800, 600, -1, -1)
$hListView = GUICtrlCreateListView("", 12, 12, 500, 500)
; Add columns
_GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 200)
_GUICtrlListView_InsertColumn($hListView, 1, "Column 2", 100)

For $i = 1 To 10
    For $ii = 1 To 10
        $idx = _GUICtrlListView_AddItem($hListView, $i)
        _GUICtrlListView_AddSubItem($hListView, $idx, $ii, 1)
        ConsoleWrite($i & @TAB & $ii & @CRLF)
    Next
Next

GUISetState(@SW_SHOW)
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            GUIDelete()
            ExitLoop
    EndSwitch
    Sleep(10)
WEnd


$Form2 = GUICreate("Example 2", 800, 600, -1, -1)
$hListView = GUICtrlCreateListView("", 12, 12, 500, 500)
; Add columns
_GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 200)
_GUICtrlListView_InsertColumn($hListView, 1, "Column 2", 100)

_GUICtrlListView_EnableGroupView($hListView)
For $i = 1 To 10
    _GUICtrlListView_InsertGroup($hListView, -1, $i, $i)
    For $ii = 1 To 10
        $idx = _GUICtrlListView_AddItem($hListView, $i)
        _GUICtrlListView_AddSubItem($hListView, $idx, $ii, 1)
        _GUICtrlListView_SetItemGroupID($hListView, $idx, $i)
        ConsoleWrite($i & @TAB & $ii & @CRLF)
    Next
Next
GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    Sleep(10)
WEnd

Cheers,

Brett

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