Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

TreeViews: Color individual rows, multiple TV support


  • Please log in to reply
11 replies to this topic
Yook
  • Members
  • 76 posts
  • Last active: Sep 23 2011 01:49 PM
  • Joined: 20 Nov 2008
This set of functions allows to change the default color of the text and/or background of any row in any treeview.

Last updated: 15 mar 2010

Listviews and treeviews can be colored simultaneously with LTVCustomColors script [ SKAN's Dropbox ], which combines listview coloring functions and treeview coloring functions described in this topic.

The idea and code are based on evl's Listview colors for individual lines (e.g. highlighting), originally from shimanov, which I ported to treeviews and added support for multiple treeviews on multiple GUIs.

Instructions:- Before coloring a treeview, you will need to call TV_Change(...) (or TV_Initialize) at least once for this treeview.

- Use TV_Change(...) to choose upon which treeview color changes are operated.

- To customize text and/or background color of a row or the entire treeview, use TV_ColorChange(...).

- As TV_Initialize(...) will not change which treeview is operated upon, you will need to call TV_Change(...) even if you used TV_Initialize(...)
Other remarks:- Specify GuiControl, N:-Redraw, TreeViewName prior to make a consequent number of color changes, and GuiControl, N:+Redraw, TreeViewName afterward.

- If your script is monitoring WM_NOTIFY messages, you will need to merge your code for these messages with the one in WM_NOTIFY() function (at comment 'ADD YOUR CODE HERE').
List of functions:TV_Change(Gui_Number=1, Control=1, Select=1) OR TV_Change(Ctrl_hWnd, "", Select=1)
Changes the treeview on which color changes will be applied. If the treeview has not been initialized, TV_Change() will call TV_Initialize() for the specified treeview.
Returns: 1 upon success, nothing if there was a problem (typically: the specified treeview was not found).
Parameters:
- Ctrl_hWnd: handle of the treeview. Second parameter must be omitted.
- Gui_Number: gui containing the treeview. Defaults to 1 if omitted.
- Control: instance number of the treeview in the gui OR ClassNN OR associated variable name. Defaults to the first treeview of specified gui if omitted.
- Select: set to 1 (default) to also make the treeview passed in parameter the one operated upon (by means of Gui, TreeView, TreeViewName). This also will change the GUI operated upon to the one containing the treeview (by means of Gui, N:Default).TV_SetColor(Index="", TextColor="", BackColor="", Redraw=1)
Changes the text and/or background color.
Returns: 1 upon success, nothing if there was a problem (typically: no treeview to operate upon).
Parameters:
- Index: Index of a row. Specify 0 or leave parameter blank to modify colors on the entire treeview.
- TextColor: new text color of the row. Specify a negative number to reset the text color. If omitted or blank, it will not be modified.
- BackColor: new background color of the row. Specify a negative number to reset the background color. If omitted or blank, it will not be modified.
- Redraw: try to set this parameter to 0 in case of slowness problems.TV_GetColor(Index, WhatColor="Text")
Retrieves the color of the provided row index or line number.Returns:the color as it was entered via TV_SetColor().
Parameters:
- Index: Index of the row from which to retrieve color.
- WhatColor: (case insensitive) specify "text" (default) to retrieve text color, specify "back" to retrieve back color.TV_Destroy(Gui_Number=1, Control=1, DeactivateWMNotify="") OR TV_Destroy(Ctrl_hWnd, "", DeactivateWMNotify= "")
Destroys all variables associated with a treeview. You may want to use this function when destroying a treeview containing a large amount of colored items. You will need to reinitialize a 'destroyed' treeview to further change its colors. This function will work even if the control doesn't exist anymore (typically destroyed by means of Gui, N:Destroy). The only exception to that is if you use TV_Destroy with the control's variable name without having previously called TV_Change (or TV_Initialize) using the variable name.
Returns: 1 upon success, nothing if there was a problem (typically: the specified treeview was not found).
Parameters:
- Ctrl_hWnd: see TV_Change.
- Gui_Number: see TV_Change.
- Control: see TV_Change.
- DeactivateWMNotify: for compatibility with scripts that may call WM_NOTIFY for other purposes, this parameter allows to choose whether to deactivate calls if no more treeview is to be monitored.TV_Initialize(Gui_Number=1, Control=1) OR TV_Initialize(Ctrl_hWnd, Control="")
This function is internal, so you usually will not need to use it. Initializes (sets variables required for color changes) the specified treeview. Does not change the treeview currently operated upon.
Returns: 1 upon success, nothing if the treeview was already initialized or there was a problem (typically: the specified treeview was not found).
Parameters:
- Ctrl_hWnd: see TV_Change.
- Gui_Number: see TV_Change.
- Control: see TV_Change.[/list]
List of extra functions:TV_GetIDFromPos(PosList, RootID="", hTV="")
Retrieves the ID of a row from its position among siblings and parents' siblings.
Returns: The ID of the row if found, nothing if not found.
Parameters:
- PosList: a list of the positions of each parents among their siblings, separated by commas. Ex: to get the 2nd child of the 3rd parent, this parameter should be "3,2".
- RootID: ID of a row to start to search from. The positions in PosList will be relative to this row.
- hTV: handle of the treeview to search in. If omitted, it will use the treeview selected by last TV_Change.TV_GetPosFromID(hItem, hTV="")
Retrieves the position among siblings and parents' siblings of a row from its ID.
Returns: The positions of the row if found, nothing if not found (same format as PosList, see TV_GetIDFromPos).
Parameters:
- hItem: the ID of the row from which to retrieve the position.
- hTV: handle of the treeview to search in. If omitted, it will use the treeview selected by last TV_Change.TV_ListID(hTV="")
Retrieves a list of the IDs in a treeview.
Parameters: hTV: handle of the treeview to search in. If omitted, it will use the treeview selected by last TV_Change.[/list]Download:TVCustomColors.ahk
Example:
#Include TVCustomColors.ahk

Gui, 4:Add, TreeView, hwndHTV1
TV_Change(4)
P1_0 := TV_Add("Zeroth parent")
P1_1 := TV_Add("First parent")
P1_1C1 := TV_Add("Parent 1's first child", P1_1)
P1_2 := TV_Add("Second parent")
P1_2C1 := TV_Add("Parent 2's first child", P1_2)
P1_2C2 := TV_Add("Parent 2's second child", P1_2)
P1_2C2C1 := TV_Add("Child 2's first child", P1_2C2)
Gui, 4:Add, TreeView, hwndHTV2
P2_1 := TV_Add("First parent")
P2_2 := TV_Add("Second parent", "", "Expand")
P2_1C1 := TV_Add("Parent 1's first child", P2_1)
P2_2C2 := TV_Add("Parent 2's second child", P2_2, "Expand")
P2_2C1 := TV_Add("Parent 2's first child", P2_2)
P2_2C2C1 := TV_Add("Child 2's first child", P2_2C2)

Gui, 4:Show

TV_Change(HTV1)
TV_SetColor(P1_1, 0xffff00, 0x0)
TV_Change(HTV2)
TV_SetColor("", 0xff00ff, 0)
TV_SetColor(TV_GetIDFromPos("2,1,1"), 0x543210, 0xea87ab)
return


4GuiClose:
4GuiEscape:
ExitApp
Return

Last updated: 15 mar 2010

Released: 15 mar 2010


  • Guests
  • Last active:
  • Joined: --
Good job, thanks very much for this! Surprised no comments as people have asked for this in the past.

Here's what it looks like with the -Lines 0x1000 extended style:

Posted Image

You can't see a selection in this style but doesn't matter too much as we;ve now got ability to manually change the selected item's color.

:D 8)

Yook
  • Members
  • 76 posts
  • Last active: Sep 23 2011 01:49 PM
  • Joined: 20 Nov 2008
Thanks for the feedback :)
Yeah, people don't often post even if they use the scripts, and I am not sure treeviews are much used.
And thank you for the trick, your pic looks nice, and it illustrates what my functions do :)

GBear
  • Members
  • 1 posts
  • Last active: Aug 17 2011 03:37 AM
  • Joined: 27 Apr 2011
It's not often I find the exact solution I need with a first-try web search. Very gratifying to find your color functions for treeviews. I'm a long time programmer, but new to Autohotkey and will no doubt use treeviews a lot.
Thanks for your sharing your efforts!

marcell
  • Guests
  • Last active:
  • Joined: --
The download link its not working for me, i need this a lot, thx.

Wade Hatler
  • Members
  • 40 posts
  • Last active: Nov 06 2014 10:46 PM
  • Joined: 28 Sep 2004

Does anyone have this script (TVCustomColors.ahk).  Looks like it got lost in the big autohotkey.net debacle, and I can't find it in any of my zips.



mrmike
  • Members
  • 45 posts
  • Last active: Jun 07 2014 04:38 PM
  • Joined: 20 Jan 2007
Is this what you're looking for?
http://dl.dropbox.co...ustomColors.ahk
Posted Image
Vista 32 Home Premium SP2

Wade Hatler
  • Members
  • 40 posts
  • Last active: Nov 06 2014 10:46 PM
  • Joined: 28 Sep 2004
That's it. Thanks.

DataLife
  • Members
  • 1022 posts
  • Last active: Nov 27 2015 01:09 AM
  • Joined: 27 Apr 2008
All links to LTVcustomcolors.ahk are dead. Does anyone have it?
Check out my scripts.  (MyIpChanger) (XPSnap) (SavePictureAs) All my scripts are tested on Windows 7, AutoHotkey 32 bit Ansi unless otherwise stated.

tmplinshi
  • Members
  • 245 posts
  • Last active: Mar 12 2015 02:29 PM
  • Joined: 06 Apr 2012
 

All links to LTVcustomcolors.ahk are dead. Does anyone have it?

 

https://gist.github....9c100a5c2efe2b6



Exaskryz
  • Members
  • 3249 posts
  • Last active: Nov 20 2015 05:30 AM
  • Joined: 23 Aug 2012

 

I tried this. It didn't work. Not even with OP's example script. I had a plain white background, all black text. Was this the right script, or has it become incompatible with the latest version (1.1.20.02) or on Win 8.1 somehow? The functions themselves are returning the value 1 which should mean they're working.



Azevedo
  • Members
  • 179 posts
  • Last active: Nov 04 2015 04:37 PM
  • Joined: 07 Mar 2012

Working! Here you go:

http://ahkscript.org...opic.php?t=2632

Credit to maestrith