Solved

How can I make a Treeview with multi-checkbox selection

Posted on 1998-07-14
17
336 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
Comment Utility
Edited text of question
0
 

Expert Comment

by:nileq
Comment Utility
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
Comment Utility
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
 
LVL 3

Expert Comment

by:Matvey
Comment Utility
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
Comment Utility
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
Comment Utility
Hi all ... everything is said at the moment.
0
 
LVL 3

Expert Comment

by:rickpet
Comment Utility
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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 3

Expert Comment

by:Matvey
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Mike, can you send a demo too? Tom.Deprez@uz.kuleuven.ac.be 10x!
0
 
LVL 3

Expert Comment

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

Expert Comment

by:ZifNab
Comment Utility
thanks, matvey, I'll a look.
0
 
LVL 10

Expert Comment

by:Lischke
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now