Jump to content

How to create a ListView Item without image (icon)?


rasim
 Share

Recommended Posts

Hi! How to create a ListView Item without image (icon)? I want to create the ListView Item without image and ListView subitem with image, but ListView Item be created with zero index of the image list control.

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

$hGUI = GUICreate("ListView example", 300, 200)

$hListView = _GUICtrlListView_Create($hGUI, "Items|SubItems", 10, 10, 280, 150, $LVS_REPORT, $WS_EX_CLIENTEDGE)

_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, _
                                          $LVS_EX_SUBITEMIMAGES, $LVS_EX_INFOTIP))

$hImage = _GUIImageList_Create(16, 16, 5, 3)
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 110)
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 131)
_GUICtrlListView_SetImageList($hListView, $hImage, 1)

_GUICtrlListView_AddItem($hListView, "Test item")
;_GUICtrlListView_SetItemImage($hListView, 0, -1)
_GUICtrlListView_AddSubItem($hListView, 0, "SubItem test", 1, 1)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd
Link to comment
Share on other sites

Zedna

Hi! Thank you for responce. But this not solved the problem. I can to remove image without a none.ico just used _GUICtrlListView_SetItemImage($hListView, 0, -1), but i don`t like this item left indention.

Link to comment
Share on other sites

  • 1 month later...

The only workaround (very kludgey) I could come up with was to create an initial zero length column and use subitems to display the info:

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.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 Create Solid BitMap", 400, 300)
    $hListView = GUICtrlCreateListView("", 2, 2, 394, 268)
    _GUICtrlListView_SetExtendedListViewStyle($hListView, $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_AddColumn($hListView, "", 0)
    _GUICtrlListView_AddColumn($hListView, "Col1", 100)
    _GUICtrlListView_AddColumn($hListView, "Col2", 100)
    
; Add items
    For $i = 0 To 2
        _GUICtrlListView_AddItem($hListView, ""); add row
        _GUICtrlListView_AddSubItem($hListView, $i, "item1", 1); add item to col1 with no solid bitmap
        _GUICtrlListView_AddSubItem($hListView, $i, "item2", 2, $i); add item to col2 with solid colour bitmap
    Next
; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc ;==>_Main

Edit: cleaned up code slightly

Edited by PartyPooper
Link to comment
Share on other sites

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

$hGUI = GUICreate("ListView example", 300, 200)

$hListView = _GUICtrlListView_Create($hGUI, "Items|SubItems", 10, 10, 280, 150, $LVS_REPORT, $WS_EX_CLIENTEDGE)

_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, _
                                          $LVS_EX_SUBITEMIMAGES, $LVS_EX_INFOTIP))

$hImage = _GUIImageList_Create(16, 16, 5, 3)
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 110)
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 131)
_GUICtrlListView_SetImageList($hListView, $hImage, 1)

_GUICtrlListView_AddItem($hListView, "Test item", _GUIImageList_GetImageCount($hImage) + 1)
;_GUICtrlListView_SetItemImage($hListView, 0, -1)
_GUICtrlListView_AddSubItem($hListView, 0, "SubItem test", 1, 1)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

GaryFrost

Thanks, but as i say above

But this not solved the problem. I can to remove image without a none.ico just used _GUICtrlListView_SetItemImage($hListView, 0, -1), but i don`t like this item left indention.

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