Sign in to follow this  
Followers 0
Reekod

My loop doesn't add any subitem ...

3 posts in this topic

#1 ·  Posted (edited)

Hi all,

I don't understand why the column 2 and 3 have no value when i press GO button

Thx for help

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 633, 454, 192, 114)
$ListView1 = GUICtrlCreateListView("", 48, 48, 538, 382)
$Go = GUICtrlCreateButton("Go", 280, 8, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Go
go()
EndSwitch
WEnd

Func Go()

_GUICtrlListView_Destroy($ListView1)
$ListView1 = GUICtrlCreateListView("", 48, 48, 538, 382)

_GUICtrlListView_InsertColumn($ListView1, 0, "Column 1", 100)
_GUICtrlListView_InsertColumn($ListView1, 1, "Column 2", 100)
_GUICtrlListView_InsertColumn($ListView1, 2, "Column 3", 100)

$i = 1
For $dropcols = 1 To 100

If $i = 1 Then
_GUICtrlListView_AddItem($ListView1, $dropcols)
Else
If $i > 3 Then
$i = 0
Else
_GUICtrlListView_AddSubItem($ListView1, $i, $dropcols, $dropcols)
EndIf
EndIf
$i = $i + 1
Next

EndFunc   ;==>Go
Edited by Reekod

Share this post


Link to post
Share on other sites



Reekod,

Because your parameters for the _GUICtrlListView_AddSubItem function were all wrong. This works for me: ;)

For $dropcols = 1 To 100

    If $i = 1 Then
        $iIndex = _GUICtrlListView_AddItem($ListView1, $dropcols)
    Else
        If $i > 3 Then
            $i = 0
        Else
            _GUICtrlListView_AddSubItem($ListView1, $iIndex, $dropcols, $i - 1)
        EndIf
    EndIf
    $i = $i + 1
Next

See if you can work out why this works and yours did not. Ask if you have any questions. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Thank you so much!

i don't knew this handle way of _GUICtrlListView_AddItem

i learn with the exemple help file :

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
$Debug_LV = False ; Check ClassName being passed to ListView functions, set to True and use a handle to another control to see it work
_Main()
Func _Main()
Local $hImage, $hListView
; Create GUI
GUICreate("ListView Add SubItem", 400, 300)
$hListView = GUICtrlCreateListView("", 2, 2, 394, 268, -1, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
GUISetState()
; Load images
$hImage = _GUIImageList_Create()
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($hListView), 0xFF0000, 16, 16))
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($hListView), 0x00FF00, 16, 16))
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($hListView), 0x0000FF, 16, 16))
_GUICtrlListView_SetImageList($hListView, $hImage, 1)
; Add columns
_GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100)
_GUICtrlListView_InsertColumn($hListView, 1, "Column 2", 100)
_GUICtrlListView_InsertColumn($hListView, 2, "Column 3", 100)
; Add items
_GUICtrlListView_AddItem($hListView, "Row 1: Col 1", 0)
_GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 2", 1, 1)
_GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 3", 2, 2)
_GUICtrlListView_AddItem($hListView, "Row 2: Col 1", 1)
_GUICtrlListView_AddSubItem($hListView, 1, "Row 2: Col 2", 1, 2)
_GUICtrlListView_AddItem($hListView, "Row 3: Col 1", 2)
; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc   ;==>_Main

i was not able to imagine that you can handle a function like this to declare the subitem in a list view

Thank you aigain !

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

  • Similar Content

    • Mithrandir
      By Mithrandir
      First of all, I am starting with GUIs but reading examples from the helpfile as well as the forum I made an script in which I have a listview that is going to be populated with user input and sorted at any given moment. When I sort it by the first or second column with the data that was already set when starting the script (1|D,2|C,4|A,3|D ) It sorts correctly but when I add a new element it doesn't sort it right, it seems it dismisses the new entered data. Here is a small example of my code to show the issue:


      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> $Form1_1 = GUICreate("Form1", 969, 569, 209, 134) $ListView1 = GUICtrlCreateListView("Col1|Col2", 32, 128, 353, 321, -1, $LVS_EX_CHECKBOXES) _GUICtrlListView_RegisterSortCallBack($ListView1) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 115) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 115) $ListView1_0 = GUICtrlCreateListViewItem("1|D", $ListView1) $ListView1_1 = GUICtrlCreateListViewItem("2|C", $ListView1) $ListView1_2 = GUICtrlCreateListViewItem("4|A", $ListView1) $ListView1_3 = GUICtrlCreateListViewItem("3|B", $ListView1) $bElim = GUICtrlCreateButton("Delete element(s)", 176, 464, 201, 25) $elem = GUICtrlCreateInput("Element", 88, 16, 241, 21) $bAdd = GUICtrlCreateButton("Add letter", 112, 48, 201, 33) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE _GUICtrlListView_UnRegisterSortCallBack($ListView1) Exit Case $ListView1 _GUICtrlListView_SortItems($ListView1, GUICtrlGetState($ListView1)) Case $bElim $i = 0 $cantitems = _GUICtrlListView_GetItemCount(GUICtrlGetHandle($ListView1)) While $i <= $cantitems If _GUICtrlListView_GetItemChecked(GUICtrlGetHandle($ListView1), $i) Then _GUICtrlListView_DeleteItem(GUICtrlGetHandle($ListView1), $i) Else $i += 1 EndIf WEnd Case $bAdd $number = Random(0, 100, 1) $handlelista = GUICtrlGetHandle($ListView1) _GUICtrlListView_AddItem($handlelista, $number) _GUICtrlListView_AddSubItem($handlelista, _GUICtrlListView_GetItemCount(GUICtrlGetHandle($ListView1)) - 1, GUICtrlRead($elem), 1) EndSwitch WEnd
      Note that if you delete all the elements that are set after the script started and you add new ones, it doesn't sort them.
      What's wrong? Thanks for your help!