When I have a TreeViewGadget with option #PB_Tree_AlwaysShowSelection, is there a posibility to change the color of the bar when the gadget is out of focus?
What I mean: Can I change the pale greyish color when an item is selected but the gadget isn't active.
Thanks in advance!
Treeview color
Re: Treeview color
I have found some kind of hack to prevent turning the color from
blue to grey by "misusing" the attribute TVIS_DROPHILITED which
keeps an item's background blue even if loosing focus. I have used
this trick already 5 years ago to allow the multiselection of items in
a TreeGadget...
My code example even allows you to toggle between normal and
highlighted mode to see the difference:
blue to grey by "misusing" the attribute TVIS_DROPHILITED which
keeps an item's background blue even if loosing focus. I have used
this trick already 5 years ago to allow the multiselection of items in
a TreeGadget...

My code example even allows you to toggle between normal and
highlighted mode to see the difference:
Code: Select all
EnableExplicit
Procedure HighlightItem(NodeID.I, HighlightFlag.I)
Protected ItemHandle.I
Protected TVHitTest.TV_HITTESTINFO
Protected TVItem.TV_ITEM
ItemHandle = GadgetItemID(0, NodeID)
If ItemHandle <> 0
If TVHitTest\Flags <> #TVHT_ONITEMBUTTON
TVItem\Mask = #TVIF_STATE
TVItem\hItem = ItemHandle
If HighlightFlag = #True
TVItem\StateMask = #TVIS_DROPHILITED
TVItem\State = #TVIS_DROPHILITED
Else
TVItem\StateMask = #TVIS_DROPHILITED
TVItem\State = 0
EndIf
SendMessage_(GadgetID(0), #TVM_SETITEM, 0, @TVItem)
RedrawWindow_(GadgetID(0), 0, 0, #RDW_UPDATENOW)
EndIf
EndIf
EndProcedure
Define i.I
Define NodeID.I
Define TreeGadgetIsInFocus.I
OpenWindow(0, 0, 0, 150, 220, "TreeGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
TreeGadget(0, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 80, #PB_Tree_AlwaysShowSelection)
ButtonGadget(1, 10, WindowHeight(0) - 60, WindowWidth(0) - 20, 20, "Toggle focus")
CheckBoxGadget(2, 10, WindowHeight(0) - 30, WindowWidth(0) - 20, 20, "Keep blue on lost focus")
For i = 1 To 2
AddGadgetItem (0, -1, "Node "+ Str(i), 0, 0)
AddGadgetItem(0, -1, "Subnode 1", 0, 1)
AddGadgetItem(0, -1, "Subnode 2", 0, 1)
AddGadgetItem(0, -1, "Subnode 3", 0, 1)
Next i
; ----- Activate TreeGadget
SetActiveGadget(0)
; ----- Expand subnodes of first node
SetGadgetItemState(0, 0, #PB_Tree_Expanded)
; ----- Select 2nd subnode of 1st node
SetGadgetState(0, 2)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
Select EventGadget()
Case 0 ; <---- TreeGadget was clicked
If GetGadgetState(2) = #True
HighlightItem(NodeID, #False)
EndIf
Case 1 ; <---- Button was pressed
TreeGadgetIsInFocus ! 1
If TreeGadgetIsInFocus
If GetGadgetState(2)
NodeID = GetGadgetState(0)
HighlightItem(NodeID, #True)
EndIf
SetActiveGadget(1)
Else
SetActiveGadget(0)
EndIf
Case 2 ; <---- CheckBox was clicked
If GetGadgetState(2)
NodeID = GetGadgetState(0)
HighlightItem(NodeID, #True)
Else
NodeID = GetGadgetState(0)
SetGadgetState(0, NodeID)
HighlightItem(NodeID, #False)
SetActiveGadget(0)
EndIf
EndSelect
EndSelect
ForEver