Jump to content
Sign in to follow this  

GUICtrlCreateListViewItem does not work as expected

Recommended Posts

I had a problem with GUICtrlCreateListViewItem. I created a listview with 2 columns. Later, some more colums are inserted into this listview. But when I create ListviewItems with GUICtrlCreateListViewItem that have more columns than the freshly created listview, it does not create an item. However, I can change subitems anywhere using GUICtrlSetData, so I could create a new item with 2 columns and set the rest of the data later. But thats a lot of unnescessary code.

I solved the problem using _GUICtrlListViewInsertItem, which does not show such limitations.

Maybe this is of interest to others, maybe sombody fixes GUICtrlCreateListViewItem, maybe someone tells me what I did wrong. Nevertheless, here is some example code:

#include <GUIConstants.au3>
#Include <GuiListView.au3>
Global $Form1           = GUICreate("Example",      695, 700, 195, 118)
Global $ListView        = GUICtrlCreateListView("Status    |Test",  16, 170, 530, 460, BitOR($LVS_REPORT,$LVS_NOSORTHEADER,$LVS_SHOWSELALWAYS), BitOR($WS_EX_CLIENTEDGE,$LVS_EX_FULLROWSELECT))
Global $BtnAdd          = GUICtrlCreateButton("Add",                        568, 190, 113, 30, 0)
Global $BtnChange       = GUICtrlCreateButton("Change 1st",                 568, 240, 113, 30, 0)
Global $BtnInsert       = GUICtrlCreateButton("Insert",                     568, 290, 113, 30, 0)

For $i =  1 to Random(2,5)
    _GUICtrlListViewInsertColumn($ListView, 1, $i & ".Test", 2, 50)
$test = "test1"
$firstItem = GUICtrlCreateListViewItem ( $test, $ListView )

While 1 ; Main loop, GUI-manager
        $g_msg = GUIGetMsg()
        Switch $g_msg
            Case $GUI_EVENT_CLOSE
            Case $BtnAdd
            Case $BtnChange
            Case $BtnInsert
Func _add()
    $test = InputBox("Test", "Please insert listviewitem data:", $test)
    GUICtrlCreateListViewItem ( $test, $ListView )

Func _insert()
    $test = InputBox("Test", "Please insert listviewitem data:", $test)
    _GUICtrlListViewInsertItem($ListView, -1, $test)

Func _change()
    $test = InputBox("Test", "Please insert listviewitem data:", $test)
    GUICtrlSetData($firstItem, $test)

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...