Jump to content

Using _GUICtrlListView_Create on a Tab


Recommended Posts

Hi All,

I reported something in the BugTracker which i believe is a bug but they closed is as No Bug..

As a solution JPM told me to use _GUICtrlListView_Create instead .. but with his example the listview is on every tab.. but when i change $hWnd to $Tab1 there is no listview at all..

Could someone give me a solution ?

#Region
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Add_Constants=n
#EndRegion

#include <GUIConstantsEx.au3>
#Include <GuiListView.au3>
#Include <GuiImageList.au3>

Local $exStyles = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES,$LVS_EX_CHECKBOXES)

$GUI = GUICreate ("Test", 400,300)
$Tab = GUICtrlCreateTab(10,10, 380,280)
$Tab1 = GUICtrlCreateTabItem("Tab1")

$List = _GUICtrlListView_Create ($Tab1, "", 20,40,360,200, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
;$List = GUICtrlCreateListView ("", 20,40,360,200, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
_GUICtrlListView_SetExtendedListViewStyle($list, $exStyles)

_AddDrives ()

$Button1 = GUICtrlCreateButton("Delete", 280, 260, 100, 20)
$Button2 = GUICtrlCreateButton("Add", 180, 260, 100, 20)
$Tab2 = GUICtrlCreateTabItem("Tab2")
GuiCtrlCreateLabel("Tab 2", 20,40,100,20)

GUISetState ()

$hImage = _GUIImageList_Create(16, 16, 5, 3)
For $i = 1 to 26
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 110 + $i)
Next
_GUICtrlListView_SetImageList($list, $hImage, 1)

_GUICtrlListView_AddColumn($list, "Column 1", 85)
_GUICtrlListView_AddColumn($list, "Column 2", 85)
_GUICtrlListView_AddColumn($list, "Column 3", 85)
_GUICtrlListView_AddColumn($list, "Column 4", 85)

While 1
 $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then Exit
    Switch $msg
        Case -3
            ExitLoop
        Case -50 To 0
            ContinueLoop
        Case $msg = 0
        Case $Button1
            _GUICtrlListView_DeleteAllItems($list)
        Case $Button2
            _AddDrives()
    EndSwitch
Wend

Func _AddDrives ()
    $DriveSet = ""
    $DriveSet = DriveGetDrive("ALL")
    For $i = 1 to $DriveSet[0]
        _GUICtrlListView_AddItem($list, StringUpper($driveset[$i]), 0 + $i)
                ; GUICtrlCreateListViewItem(StringUpper($DriveSet[$i]), $list)
    Next
EndFunc

Best regards,Emiel Wieldraaijer

Link to comment
Share on other sites

  • Moderators

Emiel Wieldraaijer,

Firstly, you should believe the Devs when they tell you it is not a bug! :)

Mixing the built-in commands and those from the UDFs often ends in tears - and here is why: AutoIt's built-in commands use ControlIDs which are stored in an internal array so that you do not have to deal with the normal Windows handles. AutoIt also takes care of things like tabs and so on for you - so again you do not have to concern yourself over the details of how to interact with them. The UDFs on the other hand create controls outside of AutoIt's knowledge - they are basically little seperate GUIs on the desktop. So you have to look after them - becasue AutoIt does not really know that they are there.

This is why you have your problem with the ListView on the tab. AutoIt will automatically sort out any built-in controls that you create within the tab structure, but not those created by a UDF.

Look at this example, which I hope makes it all clear:

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

; Create GUI
$hGUI = GUICreate("Test", 500, 500)

; Create tab structure
$hTab = GUICtrlCreateTab(10, 10, 480, 480)

$hTab0 = GUICtrlCreateTabItem("Tab0")
; create Built-in LV on Tab 0
$hLV_UDF_BuiltIn = GUICtrlCreateListView("Built-In", 30, 40, 440, 420)
For $i = 1 To 10
    GUICtrlCreateListViewItem($i, $hLV_UDF_BuiltIn)
Next

$hTab1 = GUICtrlCreateTabItem("Tab1")

GUISetState()

; create UDF LV on Tab 1
$hLV_UDF = _GUICtrlListView_Create($hGUI, "UDF", 30, 40, 440, 420)
WinSetState($hLV_UDF, "", @SW_HIDE)

For $i = 1 To 10
    _GUICtrlListView_AddItem($hLV_UDF, $i)
Next

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hTab
            ; We need to hide/show the UDF LV - AutoIt looks after the built-in version
            If GUICtrlRead($hTab) = 1 Then
                WinSetState($hLV_UDF, "", @SW_SHOW)
            Else
                WinSetState($hLV_UDF, "", @SW_HIDE)
            EndIf
    EndSwitch
WEnd

I hope that helps you see what is going on - and solves your problem as well. :idea:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

@Melba23

Off course the Devs are allways right :idea:

You knwo there are two rules

Rule 1 : A dev is always right

Rule 2 : If a dev is not right, he will fallback to rule 1 :)

Thanks for the good explaination

I tried to do same as you did in your example and your example shows me exactly what i was doing wrong..

case $hTab instead of a case statement to the tab directly

Thanks

Best regards,

Emiel

Best regards,Emiel Wieldraaijer

Link to comment
Share on other sites

  • Moderators

Emiel Wieldraaijer,

Glad I could help! :idea:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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