Jump to content
faustf

add icon in listview

Recommended Posts

hi guys  is possible insert icon with this costruct  GUICtrlCreateListView  thankz

 

 

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>

Example()

Func Example()
    GUICreate("listview items", 220, 250, 100, 200, -1, $WS_EX_ACCEPTFILES)
    GUISetBkColor(0x00E0FFFF) ; will change background color

    Local $idListview = GUICtrlCreateListView("col1  |col2|col3  ", 10, 10, 200, 150) ;,$LVS_SORTDESCENDING)
    Local $idButton = GUICtrlCreateButton("Value?", 75, 170, 70, 20)
    _GUICtrlListView_BeginUpdate($idListview)
    For $i = 0 To 10 - 1
        Local $idItem1 = GUICtrlCreateListViewItem("item2|col22|col23", $idListview)
        $hImage = _GUIImageList_Create(16, 16)
        _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 110)
        _GUICtrlListView_SetImageList($idListview, $hImage, 1)

        If Not Mod($i, 2) Then
            ;Even
            GUICtrlSetBkColor(-1, 0xffffff)
        Else
            ;Odd
            GUICtrlSetBkColor(-1, 0xe6e6e6)
        EndIf

    Next
    _GUICtrlListView_EndUpdate($idListview)
    GUICtrlCreateInput("", 20, 200, 150)
    GUICtrlSetState(-1, $GUI_DROPACCEPTED) ; to allow drag and dropping
    GUISetState(@SW_SHOW)

    GUICtrlDelete($idItem1)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

            Case $idButton
                MsgBox($MB_SYSTEMMODAL, "listview item", GUICtrlRead(GUICtrlRead($idListview)), 2)

            Case $idListview
                MsgBox($MB_SYSTEMMODAL, "listview", "clicked=" & GUICtrlGetState($idListview), 2)

        EndSwitch
    WEnd
EndFunc   ;==>Example

 

Share this post


Link to post
Share on other sites

Take a look at the example of function _GUIImageList_AddIcon  Maybe this is what you are looking for.

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

Example()

Func Example()
    Local $hGui, $idListview, $hImage
    Local $iStylesEx = BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)

    $hGui = GUICreate("ImageList AddIcon", 400, 300)
    $idListview = _GUICtrlListView_Create($hGui, "", 2, 2, 394, 268, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
    _GUICtrlListView_SetExtendedListViewStyle($idListview, $iStylesEx)
    GUISetState(@SW_SHOW)

    ; Load images
    $hImage = _GUIImageList_Create(16, 16, 5, 3)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 110)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 131)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 165)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 168)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 137)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 146)
    _GUICtrlListView_SetImageList($idListview, $hImage, 1)

    ; Add columns
    _GUICtrlListView_AddColumn($idListview, "Column 1", 120)
    _GUICtrlListView_AddColumn($idListview, "Column 2", 100)
    _GUICtrlListView_AddColumn($idListview, "Column 3", 100)

    ; Add items
    _GUICtrlListView_AddItem($idListview, "Row 1: Col 1", 0)
    _GUICtrlListView_AddSubItem($idListview, 0, "Row 1: Col 2", 1, 1)
    _GUICtrlListView_AddSubItem($idListview, 0, "Row 1: Col 3", 2, 2)
    _GUICtrlListView_AddItem($idListview, "Row 2: Col 1", 1)
    _GUICtrlListView_AddSubItem($idListview, 1, "Row 2: Col 2", 1, 2)
    _GUICtrlListView_AddItem($idListview, "Row 3: Col 1", 2)
    _GUICtrlListView_AddItem($idListview, "Row 4: Col 1", 3)
    _GUICtrlListView_AddItem($idListview, "Row 5: Col 1", 4)
    _GUICtrlListView_AddSubItem($idListview, 4, "Row 5: Col 2", 1, 3)
    _GUICtrlListView_AddItem($idListview, "Row 6: Col 1", 5)
    _GUICtrlListView_AddSubItem($idListview, 5, "Row 6: Col 2", 1, 4)
    _GUICtrlListView_AddSubItem($idListview, 5, "Row 6: Col 3", 2, 3)

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example

 


Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Share this post


Link to post
Share on other sites

is  possible only with  this construct ?

; Add items
    _GUICtrlListView_AddItem($idListview, "Row 1: Col 1", 0)
    _GUICtrlListView_AddSubItem($idListview, 0, "Row 1: Col 2", 1, 1)
    _GUICtrlListView_AddSubItem($idListview, 0, "Row 1: Col 3", 2, 2)
    _GUICtrlListView_AddItem($idListview, "Row 2: Col 1", 1)
    _GUICtrlListView_AddSubItem($idListview, 1, "Row 2: Col 2", 1, 2)
    _GUICtrlListView_AddItem($idListview, "Row 3: Col 1", 2)
    _GUICtrlListView_AddItem($idListview, "Row 4: Col 1", 3)
    _GUICtrlListView_AddItem($idListview, "Row 5: Col 1", 4)
    _GUICtrlListView_AddSubItem($idListview, 4, "Row 5: Col 2", 1, 3)
    _GUICtrlListView_AddItem($idListview, "Row 6: Col 1", 5)
    _GUICtrlListView_AddSubItem($idListview, 5, "Row 6: Col 2", 1, 4)
    _GUICtrlListView_AddSubItem($idListview, 5, "Row 6: Col 3", 2, 3)

 

Share this post


Link to post
Share on other sites
Posted (edited)
2 hours ago, faustf said:

is it possible only with this construct ? ...

No, you can also add items in a loop :

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

Example()

Func Example()
    Local $hGui, $idListview, $hImage
    Local $iStylesEx = BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)

    $hGui = GUICreate("ImageList AddIcon", 400, 300)
    $idListview = _GUICtrlListView_Create($hGui, "", 2, 2, 394, 268, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
    _GUICtrlListView_SetExtendedListViewStyle($idListview, $iStylesEx)
    GUISetState(@SW_SHOW)

    ; Load images
    $hImage = _GUIImageList_Create(16, 16, 5, 3)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 110)
    _GUICtrlListView_SetImageList($idListview, $hImage, 1)

    ; Add columns
    _GUICtrlListView_AddColumn($idListview, "Column 1", 120)
    _GUICtrlListView_AddColumn($idListview, "Column 2", 100)
    _GUICtrlListView_AddColumn($idListview, "Column 3", 100)

    ; Add items
    For $i = 0 To 10 - 1
        _GUICtrlListView_AddItem($idListview, "Row" & $i & ":Col1", 0)
        _GUICtrlListView_AddSubItem($idListview, $i, "Row" & $i & ":Col2", 1)
        _GUICtrlListView_AddSubItem($idListview, $i, "Row" & $i & ":Col3", 2)
    Next

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example

BTW : I left the line For $i = 0 To 10 - 1 like it is, but of course that makes little sense. For $i = 1 To 10 would be better here ;).

Edited by Musashi

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Share this post


Link to post
Share on other sites

why if i build  in this mode  the icon  write only in first row ?

For $i = 0 To UBound($aIcoTerminal) - 1

            $hImage = _GUIImageList_Create(16, 16,5, 3)
            _GUIImageList_AddIcon($hImage, $aIcoTerminal[$i])
            _GUICtrlListView_SetImageList($List1, $hImage, 1)
             _GUICtrlListView_AddItem($List1, $aAppDataTerminal[$i], $i)
            ;GUICtrlCreateListViewItem($aAppDataTerminal[$i], $List1)
 
        Next

 

Share this post


Link to post
Share on other sites
Posted (edited)
On 6/16/2020 at 9:43 AM, faustf said:

why if i build  in this mode  the icon  write only in first row ?

BTW : You would have much less problems, if you would visit the Help from time to time ;).

_GUICtrlListView_AddItem($List1, $aAppDataTerminal[$i], $i)

The third parameter (here , $i) is the 0-based index of the icon in the control's image list. Since you only have one element (index 0) in the image list, the icon is only displayed if $i=0.  You loop with "For $i = 0 To ...", so only the first row gets an icon.

Try :

_GUICtrlListView_AddItem($List1, $aAppDataTerminal[$i], 0)

 

EDIT : @faustf Did my hint work, or do you have further questions?

Edited by Musashi

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...