Setting the selection color of a listview

19 posts in this topic

Achilles 1

I want to set the selection color of a listview... For example, I click a listview item and it turns hot pink instead of blue. Any ideas?

I've tried looking at _GUICtrlListView_SetTextColor, _GUICtrlListView_SetTextBkColor and _GUICtrlListView_SetOutlineColor but the first two of those are for the whole listview and the third isn't what I want.

Share this post

Link to post

Share on other sites

Monamo 3

I want to set the selection color of a listview... For example, I click a listview item and it turns hot pink instead of blue. Any ideas?

I've tried looking at _GUICtrlListView_SetTextColor, _GUICtrlListView_SetTextBkColor and _GUICtrlListView_SetOutlineColor but the first two of those are for the whole listview and the third isn't what I want.

Here's a basic example (NOTE: coded for 3.2.10.0 (work mandate - we haven't migrated versions yet) so if running 3.2.12.x, you'll likely need to change the GUIContants.au3 include to GUIConstantsEx.au3 if I remember correctly from the change notes):

Share this post

Link to post

Share on other sites

v3rt1g0 0

Hmm, how would I make this work so that any checked items ($LVS_EX_CHECKBOXES) would stay highlighted?

Right now I'm using WM_NOTIFY to check checkboxes if a row is clicked. How would I integrate the above code so that when the row is clicked, and the item is checked, the row stays highlighted as long as it is checked?

I can't seem to get this to work with multiple items selected, can it? Also, when you select one item why does it appear to have more selection area on the bottom then on the top? Basically, the text isn't centered vertically in the selected rectangle, is that fixable?

Share this post

Link to post

Share on other sites

Achilles 1

Ugh, it should be possible. I found this on the MSDN library, I don't have any idea how to implement it though.

Edit: I bet all it is a simple GUICtrlSendMsg(), but I don't know what the code would be... I looked through the ListView constants and there's definitely some that haven't been used yet.. The numbering goes up to 210 but there's not 210 constants.

Share this post

Link to post

Share on other sites

pdaughe 0

The solution you posted for changing the "blue bar" selected listview item color is GREATLY appreciated. My original search of forums didn't turn up this thread, so I spent a couple of hours Googling and read details about the owner drawn method, but sure wasn't looking forward to attempting to implement it in AutoIt!

You have saved me HOURS of work, so again, thank you!

I have also been trying to figure out a couple of other things:

1. How to get the current selection color (which may or may not be "blue", depending on the windows theme. After researching this on MSDN, it "appeared" as simple as:

which returns a color, but not the right color. I tried numerous of the other GetSysColor constants, but none of them return the typical "blue bar" color. I even tried the GetThemeSysColor function, but still couldn't retrieve the correct color. Do you have any ideas on this?

2. The other item I've been researching is how to change the color of the Listview scroll bar, but I'm not sure it can be done -- I already tried the SetSystemMetrics function and that didn't work for the Listview scoll bar. I posted a question on how to do this a couple of months ago and had zero replies, so it seems it has never been done in AutoIt. If you have any ideas how to approach this, I'd appreciate the tip.

Thanks again for your contribution.

Share this post

Link to post

Share on other sites

rover 40

The solution you posted for changing the "blue bar" selected listview item color is GREATLY appreciated. My original search of forums didn't turn up this thread, so I spent a couple of hours Googling and read details about the owner drawn method, but sure wasn't looking forward to attempting to implement it in AutoIt!

You have saved me HOURS of work, so again, thank you!

I have also been trying to figure out a couple of other things:

1. How to get the current selection color (which may or may not be "blue", depending on the windows theme. After researching this on MSDN, it "appeared" as simple as:

which returns a color, but not the right color. I tried numerous of the other GetSysColor constants, but none of them return the typical "blue bar" color. I even tried the GetThemeSysColor function, but still couldn't retrieve the correct color. Do you have any ideas on this?

2. The other item I've been researching is how to change the color of the Listview scroll bar, but I'm not sure it can be done -- I already tried the SetSystemMetrics function and that didn't work for the Listview scoll bar. I posted a question on how to do this a couple of months ago and had zero replies, so it seems it has never been done in AutoIt. If you have any ideas how to approach this, I'd appreciate the tip.

Share this post

Link to post

Share on other sites

pdaughe 0

Rover, Thank You -- what you showed me indeed works. I don't understand what's going on though. According to the MSDN documentation and AutoIt's documentation, GetSysColor returns RGB values. The comment on Siao's statement suggests its converting from RGB to BGR, but AutoIt works in RGB.

Well, even if I don't understand it, it indeed works --- I wouldn't have figured that one out on my own....

I've also seen a couple of articles about how to change the color of a ListView scrollbar, but it's beyond my current ability to be able to translate those code excerpts into AutoIt.

Maybe someone else will see this and welcome the challenge.

Thank you again Rover,

Paul

Share this post

Link to post

Share on other sites

rover 40

Rover, Thank You -- what you showed me indeed works. I don't understand what's going on though. According to the MSDN documentation and AutoIt's documentation, GetSysColor returns RGB values. The comment on Siao's statement suggests its converting from RGB to BGR, but AutoIt works in RGB.

Well, even if I don't understand it, it indeed works --- I wouldn't have figured that one out on my own....

I've also seen a couple of articles about how to change the color of a ListView scrollbar, but it's beyond my current ability to be able to translate those code excerpts into AutoIt.

Maybe someone else will see this and welcome the challenge.

Thank you again Rover,

Paul

your welcome

Siao's code converts RGB-BGR or BGR-RGB

many ways of doing this on the forum, the listview udf has a version in it

system colours are BGR

MSDN page for GetSysColor says it returns RGB when it actually returns BGR