Jump to content

_GUICtrlListView_SetImageList sets all rows


 Share

Recommended Posts

Hi All,

I am working on a listview with bitmaps.

I want for each row a different bitmap ( a different picture).

but my code below will edit all the rows.

What am i doing wrong?

#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GuiConstantsEx.au3>
#include <WinAPI.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

_Main()

Func _Main()
    Local $listview, $hImage

    GUICreate("ImageList AddBitmap", 400, 300)
    $listview = GUICtrlCreateListView("", 2, 2, 394, 268, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
    _GUICtrlListView_SetExtendedListViewStyle($listview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER))
    _GUICtrlListView_AddColumn($listview, "1st", 120)
    _GUICtrlListView_AddColumn($listview, "2nd", 120)

    GUISetState()

    $hImage = _GUIImageList_Create(25, 25)
    _GUIImageList_AddBitmap($hImage, "picture1.bmp")
    _GUICtrlListView_SetImageList($listview, $hImage, 1)
    _GUICtrlListView_AddItem($listview, "Item 1", 0)

    $hImage = _GUIImageList_Create(25, 25)
    _GUIImageList_AddBitmap($hImage, "picture2.bmp")
    _GUICtrlListView_SetImageList($listview, $hImage, 1)
    _GUICtrlListView_AddItem($listview, "Item 2", 0)

    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc

Greets,

lrstndm

Link to comment
Share on other sites

I found 2 little problems.
 
1) It seems that you have to create your image list first before you add rows to the listview.
2) You referenced index 0 both times you called _GUICtrlListView_AddItem (understandable given your approach, but AutoIt doesn't seem to like that)
 
Here's what I got to work:

#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GuiConstantsEx.au3>
#include <WinAPI.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

_Main()

Func _Main()
    Local $listview, $hImage

    GUICreate("ImageList AddBitmap", 400, 300)
    $listview = GUICtrlCreateListView("", 2, 2, 394, 268, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
    _GUICtrlListView_SetExtendedListViewStyle($listview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER))
    _GUICtrlListView_AddColumn($listview, "1st", 120)
    _GUICtrlListView_AddColumn($listview, "2nd", 120)

    GUISetState()

    $hImage = _GUIImageList_Create(25, 25)
    _GUIImageList_AddBitmap($hImage, "picture1.bmp")
    _GUIImageList_AddBitmap($hImage, "picture2.bmp")
    _GUICtrlListView_SetImageList($listview, $hImage, 1)

    _GUICtrlListView_AddItem($listview, "Item 1", 0)
    _GUICtrlListView_AddItem($listview, "Item 2", 1)

    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc
Edited by Artisan
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...