Sign in to follow this  
Followers 0
Dickb

GUICtrlCreateListViewItem stops working

3 posts in this topic

#1 ·  Posted (edited)

While creating a script I ran into a problem.

I have created a demonstration to show my problem.

Start the application, select List in the main window.

Now click Add and a row is added.

Select Update and then Done.

Now click Add again and NO row is added.

Goes wrong in the stable version and beta 75.

If you disable the GUIDelete in the Update() function everything works. (beside that the update windows stays on screen).

Am I overlooking something?

Thanks for the support, Dick

For some reason the "Code" won't indent any more so please make it readable with Tidy

#include <GUIConstants.au3>

Opt("MustDeclareVars", 1)

Main()

Exit

Func Main()
    Local $Gui_1, $List, $Done, $msg1
    
    $Gui_1 = GuiCreate("Main", 200, 50)
    $List = GuiCtrlCreateButton("List",  10, 10, 80, 30)
    $Done = GuiCtrlCreateButton("Done", 100, 10, 80, 30)
    GuiSetState(@SW_SHOW)
    
    While 1
        $msg1 = GuiGetMsg()
        Select
            Case $msg1 = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg1 = $Done
                ExitLoop
            Case $msg1 = $List
                List()
            EndSelect
    WEnd
EndFunc

Func Update()
    Local $Gui_2, $Done, $msg2
    
    $Gui_2 = GuiCreate("Update", 200, 50)
    $Done = GuiCtrlCreateButton("Done", 10, 10, 80, 30)
    GuiSetState(@SW_SHOW)
    
    While 1
        $msg2 = GuiGetMsg()
        Select
            Case $msg2 = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg2 = $Done
                ExitLoop
        EndSelect
    WEnd

    GUIDelete($Gui_2)
EndFunc

Func List()
    Local $Gui_3, $listview, $Update, $Add, $Done, $msg3
    
    $Gui_3 = GuiCreate("GroupList", 400, 200)
    $listview  = GuiCtrlCreateListView("col1|col2|col3", 0, 0, 400, 150, -1, $LVS_EX_GRIDLINES)
    GUICtrlCreateListViewItem("line1|data1|more1", $listview)
    $Update = GuiCtrlCreateButton("Update", 10, 160, 80, 30)
    $Add = GuiCtrlCreateButton("Add", 100, 160, 80, 30)
    $Done = GuiCtrlCreateButton("Done", 200, 160, 80, 30)
    GuiSetState(@SW_SHOW)

    While 1
        $msg3 = GuiGetMsg()
        Select
            Case $msg3 = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg3 = $Done
                ExitLoop
            Case $msg3 = $Update
                Update()
            Case $msg3 = $Add
                GUICtrlCreateListViewItem("line2|data2|more2", $listview)
        EndSelect
    WEnd
        
    GUIDelete($Gui_3)
EndFunc
Edited by Dickb

Share this post


Link to post
Share on other sites



Cause you deleted the 'current gui' you have to select the next current gui (cause there are still more than 1) with "GUISwitch()".

Try this:

#include <GUIConstants.au3>

Opt("MustDeclareVars", 1)

Global $Gui_1, $Gui_2, $Gui_3; <-
Main()

Exit

Func Main()
Local $List, $Done, $msg1

$Gui_1 = GuiCreate("Main", 200, 50)
$List = GuiCtrlCreateButton("List", 10, 10, 80, 30)
$Done = GuiCtrlCreateButton("Done", 100, 10, 80, 30)
GuiSetState(@SW_SHOW)

While 1
$msg1 = GuiGetMsg()
Select
Case $msg1 = $GUI_EVENT_CLOSE
ExitLoop
Case $msg1 = $Done
ExitLoop
Case $msg1 = $List
List()
EndSelect
WEnd
EndFunc

Func Update()
Local $Done, $msg2

$Gui_2 = GuiCreate("Update", 200, 50)
$Done = GuiCtrlCreateButton("Done", 10, 10, 80, 30)
GuiSetState(@SW_SHOW)

While 1
$msg2 = GuiGetMsg()
Select
Case $msg2 = $GUI_EVENT_CLOSE
ExitLoop
Case $msg2 = $Done
ExitLoop
EndSelect
WEnd

GUIDelete($Gui_2)
GUISwitch($Gui_3); <- this or next line
;GuiSetState(@SW_SHOW, $Gui_3)
EndFunc

Func List()
Local $listview, $Update, $Add, $Done, $msg3

$Gui_3 = GuiCreate("GroupList", 400, 200)
$listview = GuiCtrlCreateListView("col1|col2|col3", 0, 0, 400, 150, -1, $LVS_EX_GRIDLINES)
GUICtrlCreateListViewItem("line1|data1|more1", $listview)
$Update = GuiCtrlCreateButton("Update", 10, 160, 80, 30)
$Add = GuiCtrlCreateButton("Add", 100, 160, 80, 30)
$Done = GuiCtrlCreateButton("Done", 200, 160, 80, 30)
GuiSetState(@SW_SHOW)

While 1
$msg3 = GuiGetMsg()
Select
Case $msg3 = $GUI_EVENT_CLOSE
ExitLoop
Case $msg3 = $Done
ExitLoop
Case $msg3 = $Update
Update()
Case $msg3 = $Add
GUICtrlCreateListViewItem("line2|data2|more2", $listview)
EndSelect
WEnd

GUIDelete($Gui_3)
EndFunc

Regards ;)

Holger

Share this post


Link to post
Share on other sites

Oops, you are right.

Thanks.

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