Jump to content

color question GUICtrlCreateListView() and _GUICtrlListView_Create()


Recommended Posts

With GUICtrlCreateListView() I can create a listview with different colors for different rows:

Global $GUI = GUICreate("gui", 250, 250)
Global $hListView = GUICtrlCreateListView("column1|column2|column3", 5, 5, 200, 200)

GUICtrlCreateListViewItem("row1|row1|row1", $hListView)
GUICtrlSetBkColor(-1, 0xFFFF00)
GUICtrlCreateListViewItem("row2|row2|row2", $hListView)
GUICtrlSetBkColor(-1, 0xFF0000)
GUICtrlCreateListViewItem("row3|row3|row3", $hListView)
GUICtrlSetBkColor(-1, 0x00FF00)

GUISetState(@SW_SHOW)

Do
Until GUIGetMsg() = -3

But how do we achieve the same result with _GUICtrlListView_Create() ?

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

Global $GUI = GUICreate("gui", 250, 250)

Global $hListView = _GUICtrlListView_Create($GUI, "", 5, 5, 200, 200)

_GUICtrlListView_InsertColumn($hListView, 0, "column1", 60)
_GUICtrlListView_InsertColumn($hListView, 1, "column2", 60)
_GUICtrlListView_InsertColumn($hListView, 2, "column3", 60)

_GUICtrlListView_AddItem($hListView, "row1", 0)
_GUICtrlListView_AddSubItem($hListView, 0, "row1", 1)
_GUICtrlListView_AddSubItem($hListView, 0, "row1", 2)

_GUICtrlListView_AddItem($hListView, "row2", 1)
_GUICtrlListView_AddSubItem($hListView, 1, "row2", 1)
_GUICtrlListView_AddSubItem($hListView, 1, "row2", 2)

_GUICtrlListView_AddItem($hListView, "row3", 2)
_GUICtrlListView_AddSubItem($hListView, 2, "row3", 1)
_GUICtrlListView_AddSubItem($hListView, 2, "row3", 2)

GUISetState(@SW_SHOW)

Do
Until GUIGetMsg() = -3

Is it possible? I found this function _GUICtrlListView_SetTextBkColor() but it only sets the same color for all items in the list. So no multi-colored lines like in the first example.

Link to comment
Share on other sites

Thanks for these examples although I couldn't get it to achieve the results I need which is to change the background color of the actual row.

But that's pretty massive code to simply change the font color though. With GUICtrlCreateListView() I'd be able to do that with one line of code. Does that mean there's no "easy" way to do this with _GUICtrlListView_Create()?

Is it a good idea to use GUICtrlCreateListView() and then still use some of the _GUICtrlListView_ UDF's on a listview that was created with GUICtrlCreateListView()? Or is it recommended to use _GUICtrlListView_ for everything? Because then I could have the best of both worlds guess.

Edited by Adams100
Link to comment
Share on other sites

You do NOT need to use _GUICtrlListView_Create to use the UDF functions with a listview. It doesn't even make it easier to use that over the native version, you just need to use the handle of the control created with GUICtrlCreateListview instead of the control ID. Even saying that you'd only need the handle for certain of the functions in the Listview UDF, but it's safer to use the handle for all of them because then you don't have to remember which ones cause issues when you use the control ID. BTW, to get the handle of the listview you'd use GUICtrlGetHandle() and pass that handle to all the listview UDF functions.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Another difference between _GUICtrlListView_Create() and native control is:

- native ListView has limit 65535 items due to limit of 65535 controls inside one AutoIt's application and each item is one control (ID)

- UDF ListView is slower (big difference!) especially seen with many items - you can manually optimize UDFs for creating UDF items though

Link to comment
Share on other sites

BrewManNH, thanks for the tip about GUICtrlGetHandle() because I was using the control id.

And Zedna, thanks for that info. Now the choice is clear. Native is what I want, mainly for the speed. The 65535 limit is more than enough for my current needs.

Previously I thought I had to use the UDF _GUICtrlListView_Create() in order to be able to use the other useful _GUICtrlListView_ UDF's. But now that I know those UDF's will work with the Native ListView then I'm all good. Thanks.

Link to comment
Share on other sites

The 65535 limit only applies to the listview control if you're using the native GUICtrlCreateListViewItem, it doesn't apply if you're using the UDF function to add them. The listview itself can hold more items than the AutoIt limit regardless of how it is created, it's just you'd run out of control IDs if you use the native function to add the items.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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