Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Treeview with bold nodes

Posted on 1999-01-20
9
Medium Priority
?
1,583 Views
Last Modified: 2010-05-18
I'd like to do a treeview where the currently selected node and it's parents are drawn with bold text
(maybe even in color?). so it would be more obvious what path is currently selected.
any hints???
I use delphi 3.01  
0
Comment
Question by:pwyss
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 3

Expert Comment

by:philipleighs
ID: 1362551
I think I saw a free owner draw tree view on DSP.
Try a search on http://sunsite.icm.edu.pl/delphi/
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1362552
Look at Brad Stowers' Homepage (http://members.aye.net/~bstowers/delphi/). There you will find extended Tree-/List-View components, which should be able to do what you need.

Please tell me if that helped...

Regards, Madshi.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1362553
Try this:

- Put a TreeView compontent on your form and add some items to it
- Implement the OnCustomDrawItem Eventhandler (See CustomDrawItem under Events in the Object Inspector):


procedure TForm1.TreeView1CustomDrawItem(Sender: TCustomTreeView;
  Node: TTreeNode; State: TCustomDrawState; var DefaultDraw: Boolean);
var r: TRect;
begin
  if Node = Sender.Selected then
    with Sender.Canvas do
    begin
      Font.Color := clRed;
      Font.Style := [fsUnderline];
    end;
  DefaultDraw := True;
end;


In this example only the selected item is modified. Of course you can change the code to your needs.

Good luck!!!

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 20

Expert Comment

by:Madshi
ID: 1362554
Hi Epsylon, you're solution is correct. But I guess it works only with Delphi4, right?

Regards, Madshi.
0
 

Author Comment

by:pwyss
ID: 1362555
Epsylon, unfortunatly madshi is rigth, in Delphi 3 there is no OnCustomDrawItem Event in TreeView. Guess I have to look at the components on the net...
[or are there any other proposals ??? like deriving a class from TTreeView (TCustomTreeView???) and overriding one or two methodes... ]

thanx anyway
patrick

ps: i will add a comment if any of the proposed componets work...
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1362556
Maybe you can derive a class and override the Delphi 3 properties and methods with those of Delphi 4. I don't know what the code of Delphi 3 looks like...

I will look into it later this day. Have to install my second computer first.

0
 

Author Comment

by:pwyss
ID: 1362557
Epsylon: the one you told me is still in beta, I downloaded it, but didn't take a look at it until now.

But I found something, that works on http://sunsite.icm.edu.pl/delphi/:

http://members.tripod.com/~rublin/ztree/ztree.html

only question remaining is how does this work. if someone explains this to me he can have the points.

procedure TZTreeView.Bold(node : TTreeNode);
var lev,i : Integer;
begin
    SetNodeState(node, TVIS_BOLD);
end;

procedure TZTreeView.SetNodeState(node : TTreeNode; State : Integer);
var
  tvi  : TTVItem;
begin
  FillChar(tvi, Sizeof(tvi), 0);
  tvi.hItem := node.ItemID;
  tvi.mask := TVIF_STATE;
  tvi.stateMask := TVIS_BOLD;
  tvi.state := State;
  TreeView_SetItem(node.Handle, tvi);
  Change(Node);
end;

question:
TTVItem is a packed record:
  TTVItemA = packed record
    mask: UINT;
    hItem: HTreeItem;
    state: UINT;
    stateMask: UINT;
    pszText: PAnsiChar;
    cchTextMax: Integer;
    iImage: Integer;
    iSelectedImage: Integer;
    cChildren: Integer;
    lParam: LPARAM;
  end;

seems to be some windows API stuff. Anybody knows what these fields are about, or where I can get information about this?

0
 
LVL 13

Accepted Solution

by:
Epsylon earned 300 total points
ID: 1362558
You can not change colors with this.
The API stuff can be found in the Win32 Programmer's Reference help file. Delphi 3 does not include this file if I'm correct.


Here is how the code works.

Add a TreeView (with some items) and 2 buttons to a new form.
Then add the following code:


procedure SetNodeState(node : TTreeNode; State : Integer);
var
  tvi: TTVItem;
begin
  FillChar(tvi, Sizeof(tvi), 0);  // fill the record with zeros
  tvi.hItem := node.ItemID;       // assign the node id to the record
  tvi.mask := TVIF_STATE;         // You only want to change the state
  tvi.stateMask := TVIS_BOLD;     // Only allow bold (or normal)
  tvi.state := State;             // copy the wanted state into the record
  TreeView_SetItem(node.Handle, tvi);   // change the node
//  Change(Node);                 // I don't need this in Delphi 4, maybe Delphi 3 does
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
// set the selected node to bold
  SetNodeState(TreeView1.Selected, TVIS_BOLD);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
// set the selected node to normal
  SetNodeState(TreeView1.Selected, 0);
end;

0
 

Author Comment

by:pwyss
ID: 1362559
thank you!

the Change() call is to make the treeview call it's FOnChange() [send the OnCHange event], but I don't need this...

patrick
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question