Jump to content

GUI with tab and listview acts strange


HighGuy
 Share

Recommended Posts

Hi,

I have a problem with one of my GUIs that's using tabs and a listview. It took me quite a long time to figure out that using a listview inside a tab was responsible for the problem. Can anyone confirm this behavior on his computer?

#include <GUIConstants.au3>

$LVM_DELETEALLITEMS = 0x1009
$LVM_SETCOLUMNWIDTH = 0x101E

GUICreate("listview items", 250, 300, -1, -1,-1,$WS_EX_ACCEPTFILES)

; comment out the following two lines to see the difference
$tTab = GUICtrlCreateTab(10, 10, 220, 250)
$tItem1 = GUICtrlCreateTabitem("Tab1")

$listview = GuiCtrlCreateListView ("col1  |col2|col3  ",30,40,180,110)
$add = GuiCtrlCreateButton ("Add Item",75,170,120,20)
$clear = GuiCtrlCreateButton ("Clear list",75,200,120,20)
$resize = GuiCtrlCreateButton ("Resize columns",75,230,120,20)

$item1=GuiCtrlCreateListViewItem("item2|col22|col23",$listview)
$item2=GuiCtrlCreateListViewItem("item1|col12|col13",$listview)
$item3=GuiCtrlCreateListViewItem("item3|col32|col33",$listview)

$tItem2 = GUICtrlCreateTabitem("Empty tab2")

GuiSetState()

Do
  $msg = GuiGetMsg ()
    
   Select
      Case $msg = $add
         $itemX=GuiCtrlCreateListViewItem("small width|medium width--------------|large width-----------------------------------",$listview)
      Case $msg = $clear
         GuiCtrlSendMsg($listview, $LVM_DELETEALLITEMS,0,0)
      Case $msg = $resize
            GUICtrlSendMsg($listview, $LVM_SETCOLUMNWIDTH, 0, -1); set column 1 to optimal width
            GUICtrlSendMsg($listview, $LVM_SETCOLUMNWIDTH, 1, -1); set column 2 to optimal width
            GUICtrlSendMsg($listview, $LVM_SETCOLUMNWIDTH, 2, -1); set column 3 to optimal width
      Case $msg = $listview
         MsgBox(0,"listview", "clicked="& GuiCtrlGetState($listview),2)
   EndSelect
Until $msg = $GUI_EVENT_CLOSE

Start playing around with the buttons and you'll see what I mean.

If you comment out the tab-creation the problem is gone.

Link to comment
Share on other sites

Hi,

I have a problem with one of my GUIs that's using tabs and a listview. It took me quite a long time to figure out that using a listview inside a tab was responsible for the problem. Can anyone confirm this behavior on his computer?

#include <GUIConstants.au3>

$LVM_DELETEALLITEMS = 0x1009
$LVM_SETCOLUMNWIDTH = 0x101E

GUICreate("listview items", 250, 300, -1, -1,-1,$WS_EX_ACCEPTFILES)

; comment out the following two lines to see the difference
$tTab = GUICtrlCreateTab(10, 10, 220, 250)
$tItem1 = GUICtrlCreateTabitem("Tab1")

$listview = GuiCtrlCreateListView ("col1  |col2|col3  ",30,40,180,110)
$add = GuiCtrlCreateButton ("Add Item",75,170,120,20)
$clear = GuiCtrlCreateButton ("Clear list",75,200,120,20)
$resize = GuiCtrlCreateButton ("Resize columns",75,230,120,20)

$item1=GuiCtrlCreateListViewItem("item2|col22|col23",$listview)
$item2=GuiCtrlCreateListViewItem("item1|col12|col13",$listview)
$item3=GuiCtrlCreateListViewItem("item3|col32|col33",$listview)

$tItem2 = GUICtrlCreateTabitem("Empty tab2")

GuiSetState()

Do
  $msg = GuiGetMsg ()
    
   Select
      Case $msg = $add
         $itemX=GuiCtrlCreateListViewItem("small width|medium width--------------|large width-----------------------------------",$listview)
      Case $msg = $clear
         GuiCtrlSendMsg($listview, $LVM_DELETEALLITEMS,0,0)
      Case $msg = $resize
            GUICtrlSendMsg($listview, $LVM_SETCOLUMNWIDTH, 0, -1); set column 1 to optimal width
            GUICtrlSendMsg($listview, $LVM_SETCOLUMNWIDTH, 1, -1); set column 2 to optimal width
            GUICtrlSendMsg($listview, $LVM_SETCOLUMNWIDTH, 2, -1); set column 3 to optimal width
      Case $msg = $listview
         MsgBox(0,"listview", "clicked="& GuiCtrlGetState($listview),2)
   EndSelect
Until $msg = $GUI_EVENT_CLOSE

Start playing around with the buttons and you'll see what I mean.

If you comment out the tab-creation the problem is gone.

<{POST_SNAPBACK}>

Found the problem but you will still have a problem on resize on empty because the GuiCtrlSendMsg will not do anything about repainting the listview control

Thanks :lmao:

Link to comment
Share on other sites

Found the problem but you will still have a problem on resize on empty because the GuiCtrlSendMsg will not do anything about repainting the listview control

Thanks o:)

<{POST_SNAPBACK}>

Does this mean there'll be a fix for it in one of the next releases? :lmao:
Link to comment
Share on other sites

  • Administrators

The SendMsg stuff is low level stuff and messages are just passed from Autoit to the WinAPI without checking (too many checks). What you need to do after that is to force a redraw. AutoIt currently forces a redraw when you mess around with control states or positioning so just add this after your SendMsg statements:

GUICtrlSendMsg($listview, $LVM_SETCOLUMNWIDTH, 0, -1); set column 1 to optimal width
GUICtrlSendMsg($listview, $LVM_SETCOLUMNWIDTH, 1, -1); set column 2 to optimal width
GUICtrlSendMsg($listview, $LVM_SETCOLUMNWIDTH, 2, -1); set column 3 to optimal width
GUICtrlSetState($listview, $GUI_ENABLE)

We can look to add a GUICtrlRedraw or $GUI_REDRAW type thing in the next version.

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