Board index » kylix » Changing color of selected items in a TTreeView

Changing color of selected items in a TTreeView


2005-07-21 12:46:16 AM
kylix0
In delphi this is a pretty straight forward thing to do
in TreeView.OnDrawCustomItem Event this code works as expected
(selected items are highlighted red with yellow text)
if cdsSelected in State then
begin
treeviewMain.Canvas.Font.Color := clYellow;
treeviewMain.Canvas.Brush.Color := clRed;
end
else
begin
treeviewMain.Canvas.Font.Color := clWindowText;
treeviewMain.Canvas.Brush.Color := clWindow;
end;
Now using Klyix3 Pro the code below, placed in the OnCustomDrawItem event handler, changes the color of the item below the currently selected one, doesn't change the selected hightlight color and looks like {*word*99}, refreshing the screen constantly
if cdsSelected in State then
begin
// In Kylix TTreeView doesn't have Canvas property so......
treeviewMain.Font.Color := clYellow;
treeviewMain.Brush.Color := clRed;
end
else
begin
treeviewMain.Font.Color := clWindowText;
treeviewMain.Brush.Color := clWindow;
end;
Am I going about this the wrong way or is something else wrong?
Thanks in advance!
 
 

Re:Changing color of selected items in a TTreeView

Quote

Am I going about this the wrong way or is something else wrong?

Maybe you should actually Draw something like:
procedure TForm1.TreeView1CustomDrawItem(Sender: TCustomViewControl;
Item: TCustomViewItem; Canvas: TCanvas; const Rect: TRect;
State: TCustomDrawState; Stage: TCustomDrawStage;
var DefaultDraw: Boolean);
begin
if cdsSelected in State then
begin
DefaultDraw:=false;
Canvas.Font.Color := clYellow;
Canvas.Brush.Color := clRed;
Canvas.FillRect(Rect);
Canvas.TextOut(1,1, TTreeNode(Item).Text);
end else DefaultDraw:=True;
end;
Alternatively you might use www.soft-gems.net/VirtualTreeview/
 

Re:Changing color of selected items in a TTreeView

Thanks once again Theo, that does the trick.
I had tried setting properties for the Canvas but I
didn't do the FillRect or TextOut steps.
theo < XXXX@XXXXX.COM >wrote:
Quote

Maybe you should actually Draw something like:

procedure TForm1.TreeView1CustomDrawItem(Sender: TCustomViewControl;
Item: TCustomViewItem; Canvas: TCanvas; const Rect: TRect;
State: TCustomDrawState; Stage: TCustomDrawStage;
var DefaultDraw: Boolean);
begin
if cdsSelected in State then
begin
DefaultDraw:=false;
Canvas.Font.Color := clYellow;
Canvas.Brush.Color := clRed;
Canvas.FillRect(Rect);
Canvas.TextOut(1,1, TTreeNode(Item).Text);
end else DefaultDraw:=True;
end;


Alternatively you might use www.soft-gems.net/VirtualTreeview/
 

{smallsort}