Jump to content

Listview Item Without Icon Shows Empty Space


 Share

Recommended Posts

Hi all,

I'm trying to create a listview with subitem icons and I achieved this by simply rearranging the order of the columns, so that the first column is in the middle, thus appearing as a subitem with an icon - this method prevents the "icon clipping" that happens when using subitem icons in a listview. My issue is that when I select a row that does not have an icon, the space where the icon would be is white. Is there a way to make this transparent, so it looks like the entire row is selected?

Here's an example - click the second listview item/row to see a blank space where the icon would be.

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

_Main()

Func _Main()
    Local $hGui, $listview, $hImage
    Local $iLV_EXStyle_NoChecks = BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_DOUBLEBUFFER, $LVS_EX_HEADERDRAGDROP)

    $hGui = GUICreate("Listview Test With Icons", 400, 300)
    $listview = GUICtrlCreateListView("Col 1|Col 2|Col 3", 2, 2, 394, 268, BitOR($LVS_REPORT, $LVS_SHAREIMAGELISTS))
    _GUICtrlListView_SetExtendedListViewStyle($listview, $iLV_EXStyle_NoChecks)
    GUISetState()

    ; Create the image list
    $hImage = _GUIImageList_Create(16, 16, 5, 3)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 165)
    _GUICtrlListView_SetImageList($listview, $hImage, 1)

    ; Set the order so the first column is moved to the middle,
    ; acting like a subitem with an icon
    _GUICtrlListView_SetColumnOrder($listview, "1|0|2")
    
    ; Add the items
    GUICtrlCreateListViewItem("Item1|Item2|Item3", $listview)
    GUICtrlCreateListViewItem("Item4|Item5|Item6", $listview)
    
    ; Set an icon for just the first item
    _GUICtrlListView_SetItemImage($listview, 0, 0)

    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Main

 

Link to comment
Share on other sites

snip. don't know. your requirements seem weird to me. why can't everyone have an icon? even just a '-' character?

I see no clipping in the example that you got your code from in the Help file

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

It's going to be a list of applications which will have a column for updates that are available. If there's an update available, it shows a 'new' icon with the new version. If no update is necessary, it's just an empty subitem. And if an item with no updates available is selected, it just looks weird with this white square in the subitem. I was hoping there was some trick to make it blend in.

I've attached an image where I've selected the item without an icon and it shows the 'placeholder' where an icon would be as a white square - it just looks weird to me.

2018-01-19_10-09-17.png

Link to comment
Share on other sites

didnt try but, maybe set background color for that item as blue when selected?

I placed a white icon and it looks like this

 

screenshot - 20012018-1835.jpg

Edited by careca
Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

You might use a dirty workaround... create a zero-width column 0 and set it at the last column position

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

_Main()

Func _Main()
    Local $hGui, $listview, $hImage
    Local $iLV_EXStyle_NoChecks = BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_DOUBLEBUFFER, $LVS_EX_HEADERDRAGDROP)

    $hGui = GUICreate("Listview Test With Icons", 400, 300)
    $listview = GUICtrlCreateListView("|Col 1|Col 2|Col 3", 2, 2, 394, 268, BitOR($LVS_REPORT, $LVS_SHAREIMAGELISTS))
    _GUICtrlListView_SetExtendedListViewStyle($listview, $iLV_EXStyle_NoChecks)
    GUISetState()

    ; Create the image list
    $hImage = _GUIImageList_Create(16, 16, 5, 3)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 165)
    _GUICtrlListView_SetImageList($listview, $hImage, 1)

    ; Set the order so the first column is moved to the end
    _GUICtrlListView_SetColumnWidth($listview, 0, 0)
    _GUICtrlListView_SetColumnOrder($listview, "1|2|3|0")

    ; Add the items
    GUICtrlCreateListViewItem("|Item1|Item2|Item3", $listview)
    GUICtrlCreateListViewItem("|Item4|Item5|Item6", $listview)
    
    ; Set an icon for just the first item
    _GUICtrlListView_SetItemImage($listview, 0, 0, 2)

 
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Main

 

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

×
×
  • Create New...