Jump to content
Sign in to follow this  
eEniquEe

Possible Error with Image in List View?

Recommended Posts

eEniquEe

Hi,

I am currently working on a project, which involves ListView. And I came across a little problem... I'll be very thankful if someone can help me with it. Well... Here's the problem.

I want to have some kind of image in front of the text. So I looked in the Help File, and found this piece of code.

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>

Opt('MustDeclareVars', 1)

$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
    
    GUICreate("ListView Set Image List", 400, 300)
    $hListView = GUICtrlCreateListView("", 2, 2, 394, 268)
    GUISetState()

    ; Load images
    $hImage = _GUIImageList_Create()
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0xFF0000, 16, 16))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x00FF00, 16, 16))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x0000FF, 16, 16))
    _GUICtrlListView_SetImageList($hListView, $hImage, 1)

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

    ; Add items
    _GUICtrlListView_AddItem($hListView, "Item 1", 0)
    _GUICtrlListView_AddItem($hListView, "Item 2", 1)
    _GUICtrlListView_AddItem($hListView, "Item 3", 2)
    ;If I change the line above to _GUICtrlListView_AddItem($hListView, "Item 3", -1) it will still show a red square in front of the text 'Item 3', which means that the parameter -1 does not work as expected...
    ;_GUICtrlListView_AddItem($hListView, "Item 3", -1)

    ; Get image list handle
    MsgBox(4160, "Information", "Image List Handle: 0x" & Hex(_GUICtrlListView_GetImageList($hListView, 1)))

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc

Well, I think this is what I need. However, I just want some of the texts to have an image display in front of them, and the rest will have no image. So, I try to change the Image parameter to -1, but still, the image is shown... :x

Have I done something wrong, or is it a bug?

Thanks a lot in advance.

Share this post


Link to post
Share on other sites
KaFu

No bug, but either the Listview contains images or it does not, can't be selected per row. A workaround is to add a color matching the window itself and assign that in case you don't want anything to display.

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>

#include <WindowsConstants.au3>
#include <Winapi.au3>

Opt('MustDeclareVars', 1)

$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

    GUICreate("ListView Set Image List", 400, 300)
    $hListView = GUICtrlCreateListView("", 2, 2, 394, 268)
    GUISetState()

    ; Load images
    $hImage = _GUIImageList_Create()
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0xFF0000, 16, 16))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x00FF00, 16, 16))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x0000FF, 16, 16))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, _WinAPI_GetSysColor($COLOR_WINDOW), 16, 16))
    _GUICtrlListView_SetImageList($hListView, $hImage, 1)

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

    ; Add items
    _GUICtrlListView_AddItem($hListView, "Item 1", 0)
    _GUICtrlListView_AddItem($hListView, "Item 2", 1)
    _GUICtrlListView_AddItem($hListView, "Item 3", 4)
    ;If I change the line above to _GUICtrlListView_AddItem($hListView, "Item 3", -1) it will still show a red square in front of the text 'Item 3', which means that the parameter -1 does not work as expected...
    ;_GUICtrlListView_AddItem($hListView, "Item 3", -1)

    ; Get image list handle
    MsgBox(4160, "Information", "Image List Handle: 0x" & Hex(_GUICtrlListView_GetImageList($hListView, 1)))

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc

Share this post


Link to post
Share on other sites
kaotkbliss

_GUICtrlListView_AddItem($hListView, "Item 3", 3)

gave me a white square. While I know it's not exactly what you were after, it does make it appear there is no image.

*edit*

Kafu beat me to the punch :x

Edited by kaotkbliss

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites
eEniquEe

Ah, ok, I think I get it. ^^!

Thanks you guys sssssooo much for your help. :P

And have a good day, :x

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  

×