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

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Sabestian Caine
Posts: 528
Joined: 12 Apr 2015, 03:53

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

Post by Sabestian Caine » 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 3962 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 3962 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.


User avatar
Sabestian Caine
Posts: 528
Joined: 12 Apr 2015, 03:53

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

Post by Sabestian Caine » 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 3889 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.

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

Post by wolf_II » 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: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

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

Post by just me » 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: 528
Joined: 12 Apr 2015, 03:53

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

Post by Sabestian Caine » 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.

User avatar
Sabestian Caine
Posts: 528
Joined: 12 Apr 2015, 03:53

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

Post by Sabestian Caine » 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.

jsong55
Posts: 219
Joined: 30 Mar 2021, 22:02

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

Post by jsong55 » 29 Sep 2022, 21:49

Code: Select all

for i,v in selected_opps
LV_Colors:=new LV_Colors(LVCustomers)
for i,v in selected_customers
{
    LV_Add("",v.cust_id,v.name,v.specific_action,v.call)
    ; color those done, emailed, teamsed
    if instr(v.specific_action,"DONE")
        LV_Colors.Row(i, 0xFFF9B0)
}
Upon the first trigger of the Gui, works as intended. However, upon retrigger of the Gui, the Gui creates the listview without colors.

This is the code above that creates the Gui everytime

Code: Select all

Gui, LVCustomers: new
Gui, LVCustomers: +LabelLVCustomers
Gui, LVCustomers:Font,% "s10", Calibri
Gui, LVCustomers: Add, ListView, hwndLVCustomers gLVCustomersAct w950 h450 Grid altSubmit,ID|Name|

jsong55
Posts: 219
Joined: 30 Mar 2021, 22:02

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

Post by jsong55 » 04 Oct 2022, 23:37

Any help will be appreciated

just me
Posts: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

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

Post by just me » 05 Oct 2022, 03:33

Code: Select all

for i,v in selected_opps
   LV_Colors:=new LV_Colors(LVCustomers)
Why do you want to do it in a For-Loop? Do you create multiple ListViews?

Code: Select all

LV_Colors:=new LV_Colors(LVCustomers)
This replaces the original class with an instance of itself. Is it intended?

jsong55
Posts: 219
Joined: 30 Mar 2021, 22:02

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

Post by jsong55 » 05 Oct 2022, 23:23

Code: Select all

Gui, LVCustomers: new
Gui, LVCustomers: +LabelLVCustomers
Gui, LVCustomers:Font,% "s10", Calibri
Gui, LVCustomers: Add, ListView, hwndLVCustomers_listview vLVCustomers_listview gLVCustomers_listview w950 h450 Grid altSubmit,ID|Name|Action
Gui, LVCustomers:Default
; LV_Colors:=""
LV_Colors:=new LV_Colors(LVCustomers_listview)
for i,v in selected_opps
{
    LV_Add("",v.id,v.name,v.action)
    ; color those done, emailed, teamsed
    if instr(v.action,"DONE") or instr(v.action,"EMAILED") or instr(v.action,"TEAMSed")
        LV_Colors.Row(i, 0xFFF9B0)
}
LV_ModifyCol()
LV_ModifyCol(4,"Sort")
LV_ModifyCol(3,200)
Typo in my original question but this is how it's supposed to be

the

Code: Select all

LV_Colors:=new LV_Colors(LVCustomers_listview)
is outside the for loop

just me
Posts: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

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

Post by just me » 06 Oct 2022, 03:10

Try to change the name of the instance variable, e.g.

Code: Select all

My_Colors := New LV_Colors(LVCustomers_listview)
for i,v in selected_opps
{
    LV_Add("",v.id,v.name,v.action)
    ; color those done, emailed, teamsed
    if instr(v.action,"DONE") or instr(v.action,"EMAILED") or instr(v.action,"TEAMSed")
        My_Colors.Row(i, 0xFFF9B0)
}

jsong55
Posts: 219
Joined: 30 Mar 2021, 22:02

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

Post by jsong55 » 07 Oct 2022, 21:26

just me wrote:
06 Oct 2022, 03:10
Try to change the name of the instance variable, e.g.

Code: Select all

My_Colors := New LV_Colors(LVCustomers_listview)
for i,v in selected_opps
{
    LV_Add("",v.id,v.name,v.action)
    ; color those done, emailed, teamsed
    if instr(v.action,"DONE") or instr(v.action,"EMAILED") or instr(v.action,"TEAMSed")
        My_Colors.Row(i, 0xFFF9B0)
}
Thanks just me! It works great. I use a lot of your classes. Keep up the great work!

Post Reply

Return to “Ask for Help (v1)”