Solved

How can I make a Treeview with multi-checkbox selection

Posted on 1998-07-14
17
342 Views
Last Modified: 2010-04-04
I like very much the treeview object, but I would like to add one additionnal
feature to it.  Imagine a regular treeview with expand and collapse icons.
When you select one or multiple nodes, you have an additionnal checkbox icon beside
the expand and collapse.  So you can save only those selected with the checkbox.

 [  ]-[+]-Project 1
       |
 [X]-[-]-Project 2
          |
        [  ]-[+]-Application 1
               |
        [X]-[-]-Application 2      
0
Comment
Question by:sylvainl
  • 6
  • 4
  • 3
  • +4
17 Comments
 

Author Comment

by:sylvainl
ID: 1357908
Edited text of question
0
 

Expert Comment

by:nileq
ID: 1357909
Hi sylvainl:
That's not an easy question. You would have to create a new component derived out of TCustomTreeView, and modify the TTreeNode object. Adding the property TTreeNode.Checked isn't verry difficult but adding the graphic capabileties sertainly demands attention.
I'll see what I can do, if I have the time :)

0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1357910
The TTreeView component supports another image which should work.  Look up "StateImages" in the help file.  From Delphi's help file: "The state image appears as an additional image to the left of the item's icon."

Cheers,
JB
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 3

Expert Comment

by:Matvey
ID: 1357911
You don't have to make them yourself - there are already some trees like this:

http://bes.trendline.co.il/torry/vcl/lbcb/chkoutl.zip
"Checkoutline is just the same as the standard outline control, but has the ability to check the items."

http://bes.trendline.co.il/torry/vcl/lbcb/mstree.zip
"A TreeView that is capable of multi-selecting." (Can be the same as checkboxes...)

http://bes.trendline.co.il/torry/vcl/lbcb/treent10.zip
"TreeNT is much enhanced treeview control, which is really fast and has many new features like checkboxes, auto scrolling, hot tracking, single expand, node hints and much more."
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1357912
http://bes.trendline.co.il/torry/vcl/lbcb/outlplus.exe
"Allows you to specify different glyphs for each node in the outline."
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1357913
Hi all ... everything is said at the moment.
0
 
LVL 3

Expert Comment

by:rickpet
ID: 1357914
I would just make a glyph of a checkbox and use an overlay of a check.  Check out TImageList and overlays...

Rick
0
 
LVL 10

Accepted Solution

by:
Lischke earned 100 total points
ID: 1357915
Hi sylvainl

I'm the aouthor of TreeNT mentioned on this page and I managed to have checkboxes by listening to mouse down events and updating the stateimage. You can do it simpler.

Write an event handler for OnCollapsed and OnExpanded and use this to update a specific StateImage icon:

procedure TMainForm.TreeView1Collapsed(Sender: TObject; Node: TTreeNode);
begin
  Node.StateIndex:=ckCheckEmpty;
end;

where you define some constants like:

const ckEmpty         = 0; //: an empty image (state index must be > 0)
      ckCheckEmpty    = 1; //: an empty checkbox
      ckCheckChecked  = 2; //: a checkbox with a cross
      ckCheckDisabled = 3; //: a grayed and empty checkbox
      ckCheckGrayed   = 4; //: a grayed checkbox with a cross
      ckRadioEmpty    = 5; //: an empty radio button (circle)
      ckRadioChecked  = 6; //: a radio button with a filled circle
      ckRadioDisabled = 7; //: a grayed and empty radio button
      ckRadioGrayed   = 8; //: a grayed radio button with a filled circle

which correlate directly to images in a state image list you have to create and assign to your tree.

Nodes without an state image get 0 (zero) as stateindex, so they don't reserve any space for the image.

Hope this helps,

Ciao, Mike
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1357916
Hi Mike, I guess component writrers have their fans too ;-) So I'm one. Good thing someone plants trees here :)
0
 
LVL 10

Expert Comment

by:Lischke
ID: 1357917
Hi Matvey,

I'm pleased to read that...:-) Well, TreeNT is going to be used in lots of (even commercial) products soon. BTW: Version 2.1 is almost ready. If anyone wants a free copy, just send a mail...

Ciao, Mike
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1357918
Sure, I'd love to receive the new ver. Have you seen the Eugine Mayevski tree? BWPack? A good one too. I know it because I know Eugine... (http://bes.trendline.co.il/torry/vcl/packs/bwpack.zip)

bosism@netvision.net.il (my email)
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1357919
Mike, can you send a demo too? Tom.Deprez@uz.kuleuven.ac.be 10x!
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1357920
Zif, Mike, the BWPack also contains lots of cool stuff, a tree I mean. My advice...
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1357921
thanks, matvey, I'll a look.
0
 
LVL 10

Expert Comment

by:Lischke
ID: 1357922
Matvey, ZifNab,

the code is on the way to your mail addresses.

I'd also a lokk at the BWPack, but the tree is without source, so it is not useful for me.

Ciao, Mike
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1357923
Thank you very much Lischke.

Forgot to mention... Somebody already looked at the TeeTree? New component form TeeChart? Zif.
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1357924
Thanks! I'll look at it right away.

BWPack - I think it's with sources. You can email the author of course if there are no sources inside - what's the reason to hide them if it's freeware anyway?
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

809 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