How to change the color of ListView's rows according to their values? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
User avatar
Sabestian Caine
Posts: 420
Joined: 12 Apr 2015, 03:53

How to change the color of ListView's rows according to their values?

30 May 2019, 10:08

Hello Friends..


I have to work on MS excel to manage data. My excel sheet and data looks like this-
30_05_19 @8_13_51.PNG
30_05_19 @8_13_51.PNG (22.13 KiB) Viewed 766 times

In the above image you can see that I have used two colors in rows. One color is sky blue which indicates the positive entry. Namely, if the value in column L is positive then it turns the color of entire row to sky blue. On the other hand if the value in column L is negative then it will turn the color of entire row to orange. The same thing i want to do with ListView.

I have these codes-

Code: Select all

xl:=comobjactive("excel.application")
lastrow:=15
gui,font, s15
Gui, Add, ListView, r20 w700 grid, 1|1|10|10|20|50|100|200|500|2000|Total

loop 8
{
	
	LV_Add(col10,Round(xl.range("b" lastrow).value),Round(xl.range("c" lastrow).value),Round(xl.range("d" lastrow).value),Round(xl.range("e" lastrow).value),Round(xl.range("f" lastrow).value),Round(xl.range("g" lastrow).value),Round(xl.range("h" lastrow).value),Round(xl.range("i" lastrow).value),Round(xl.range("j" lastrow).value),Round(xl.range("k" lastrow).value),Round(xl.range("l" lastrow).value))
	LastRow++
}
p:=1
loop 11
{
	
	LV_ModifyCol(p,"AutoHDR")
	p++
}
gui,Show
When i run these codes it shows the ListView of that excel sheet like this-
30_05_19 @8_24_26.PNG
30_05_19 @8_24_26.PNG (59.67 KiB) Viewed 766 times

Now, I want to make it in similar color like excel sheet i.e. row number 2 and row number 5 which are containing negative values should turn to orange color. While all other rows except row 2 and row 5 contain positive values so they should turn to sky blue color.


How to create that effect in ListView?


Please help and guide..

Thanks a lot..
I don't normally code as I don't code normally.
YOU do what YOU want, but happens what HE wants.
YOU do what HE wants, will happen what YOU want.
User avatar
Sabestian Caine
Posts: 420
Joined: 12 Apr 2015, 03:53

Re: How to change the color of ListView's rows according to their values?

31 May 2019, 15:14

hd0202 wrote:
31 May 2019, 01:24
have a look at
https://www.autohotkey.com/boards/viewtopic.php?f=6&t=1081

Hubert
Thanks dear hd0202 for your kind reply...

But, sir please tell me how to use LV_Colors class as mentioned in above link..

I tried to use LV_Colors class like this-

Code: Select all

Gui, Add, ListView, r20 w700 grid HWNDHLV, 1|1|10|10|20|50|100|200|500|2000|Total
LV_Add("", "jack","paul")
LV_Add("", "rock","mik")
LV_Colors.Row(HLV, 1, 0xFFFFB5)
gui,show

#Include Class_LV_Colors.ahk
In the above codes i created only two rows and i want to make the color of first row to be 0xFFFFB5. But, when i run these codes it shows ListView like this-
01_06_19 @1_40_30.PNG
01_06_19 @1_40_30.PNG (24.1 KiB) Viewed 693 times
apparently, it is not changing the color of first row. Perhaps, I am not using LV_Colors class properly. Please tell me how to use it properly? Thanks a lot..
I don't normally code as I don't code normally.
YOU do what YOU want, but happens what HE wants.
YOU do what HE wants, will happen what YOU want.
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: How to change the color of ListView's rows according to their values?  Topic is solved

31 May 2019, 15:30

Try this:

Code: Select all

Gui, Add, ListView, r20 w700 grid HWNDHLV, 1|1|10|10|20|50|100|200|500|2000|Total
LV_Add("", "jack","paul")
LV_Add("", "rock","mik")
new LV_Colors(HLV).Row(1, 0xFFFFB5)
gui,show

#Include Class_LV_Colors.ahk
I hope that helps.
just me
Posts: 6674
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: How to change the color of ListView's rows according to their values?

31 May 2019, 17:35

Class_LV_Colors.ahk wrote:How to use:
  • First create a new instance of LV_Colors with MyInstance := New LV_Colors(HLV) passing the HWND of your ListView.
  • Then call MyInstance.Cell() or MyInstance.Row() to setup colours for individual cells and/or rows.
  • That's all you have to do for colouring.
?
User avatar
Sabestian Caine
Posts: 420
Joined: 12 Apr 2015, 03:53

Re: How to change the color of ListView's rows according to their values?

02 Jun 2019, 15:20

wolf_II wrote:
31 May 2019, 15:30
Try this:

Code: Select all

Gui, Add, ListView, r20 w700 grid HWNDHLV, 1|1|10|10|20|50|100|200|500|2000|Total
LV_Add("", "jack","paul")
LV_Add("", "rock","mik")
new LV_Colors(HLV).Row(1, 0xFFFFB5)
gui,show

#Include Class_LV_Colors.ahk
I hope that helps.
Thanks dear wolf_II... Now it is working... Thanks a lot...
I don't normally code as I don't code normally.
YOU do what YOU want, but happens what HE wants.
YOU do what HE wants, will happen what YOU want.
User avatar
Sabestian Caine
Posts: 420
Joined: 12 Apr 2015, 03:53

Re: How to change the color of ListView's rows according to their values?

02 Jun 2019, 15:21

just me wrote:
31 May 2019, 17:35
Class_LV_Colors.ahk wrote:How to use:
  • First create a new instance of LV_Colors with MyInstance := New LV_Colors(HLV) passing the HWND of your ListView.
  • Then call MyInstance.Cell() or MyInstance.Row() to setup colours for individual cells and/or rows.
  • That's all you have to do for colouring.
?
Thanks dear just me... I just forgot that.... Thanks a lot once again sir... :thumbup: :thumbup:
I don't normally code as I don't code normally.
YOU do what YOU want, but happens what HE wants.
YOU do what HE wants, will happen what YOU want.

Return to “Ask For Help”

Who is online

Users browsing this forum: Google [Bot], theon and 237 guests