Jump to content

Problems with GUIListView.au3


chalup
 Share

Recommended Posts

I'm currently working on the script that reads and displays the big (up to several thousand records) database. The most logical way to display the records was ListView, but unfortunately there's the limit of ~4000 items. I found out that i can add more items using _GUICtrlListViewInsertItem function from ... (although it works much slower than GUICtrlCreateListViewItem). The biggest problem however, is the fact that GUICtrlCreateListViewItem returns ControlID, that can be used for example in GUICtrlSetData, and _GUICtrlListViewInsertItem returns only item index. I also noticed that objects created by latter function behave differently. Take a look at this script:

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

Global $msg = 0

Global $mainWindow = GuiCreate("Test", 500, 400, -1, -1, $WS_SIZEBOX + $WS_MINIMIZEBOX)
Global $lv = GUICtrlCreateListView ("a|b|c|d|e|f|g|h",20, 40,470,300, BitOr( $LVS_SHOWSELALWAYS, $LVS_SINGLESEL) , BitOr ( $LVS_EX_FULLROWSELECT , $LVS_EX_GRIDLINES ) )
_GUICtrlListViewSetColumnWidth ( $lv, 0, 250 )
$item1 = _GUICtrlListViewInsertItem( $lv, -1, "FOO|0|0|0|0|0|0|0")
$item2 = GUICtrlCreateListViewItem ( "BAR|0|0|0|0|0|0|0", $lv)
GuiSetState( @SW_SHOW, $mainWindow )

While $msg <> $GUI_EVENT_CLOSE
    $msg = GUIGetMsg()

    If ( $msg == 0 ) Then
        ContinueLoop
    EndIf

    Switch $msg
        Case $item1
            MsgBox (0, "Test", "INSERT")
        Case $item2
            MsgBox (0, "Test", "CREATE")
    EndSwitch
WEnd

It creates listview with few columns and two items: one created with GUICtrlCreateListViewItem, the other one inserted with _GUICtrlListViewInsertItem. When you click the "created" item, the message box appears, but when you click the "inserted" one - nothing happens. It's a big problem for me, because i need to react on clicking the listview items and doing it in the message loop seemed the easiest solution. I hope i will be able to somehow make the "inserted" items behave like "created" ones.

Do you have any idea how can i accomplish it, or can you propose another solution for this problem?

Link to comment
Share on other sites

You must catch WM_NOTIFY and NM_XX messages by GUIRegisterMsg() This will make for all items no matter how they are were created.

Rough concept example

#include <GUIConstants.au3>
#include <GuiListView.au3>

$Form1 = GUICreate("Test", 619, 477, -1, -1)
$Group1 = GUICtrlCreateGroup(" EXE ", 16, 16, 287, 177)
$ListView1 = GUICtrlCreateListView("a|b", 25, 33, 266, 118)
GUICtrlCreateListViewItem('11|22',$ListView1)
GUICtrlCreateListViewItem('33|44',$ListView1)
GUISetState(@SW_SHOW, $Form1)
 GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events")

While 1
    $msg = GuiGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
                    EndSelect
WEnd

Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam)
    #forceref $hWndGUI, $MsgID, $wParam
    Local $tagNMHDR, $event
        $tagNMHDR = DllStructCreate("int;int;int", $lParam)
    If @error Then Return
    $event = DllStructGetData($tagNMHDR, 3)
        If $wParam = $ListView1 Then
        Select
            Case $event = $NM_CLICK
                onclick()
            Case $event = $NM_DBLCLK
                OnDoubleClick()
        EndSelect
    EndIf
EndFunc

Func onclick()
    MsgBox(0,'Clicked',_GUICtrlListViewGetItemText($ListView1,_GUICtrlListViewGetCurSel($ListView1),0))
EndFunc

Func OnDoubleClick()
    MsgBox(0,'DoubleClicked',_GUICtrlListViewGetItemText($ListView1,_GUICtrlListViewGetCurSel($ListView1),0))
EndFunc
Edited by Zedna
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...