The Wayback Machine - https://web.archive.org/web/20130129040922/http://www.codeguru.com/cpp/controls/treeview/misc-advanced/article.php/c3983/TreeView-with-ThreeState-Checkboxes.htm

TreeView with Three-State Checkboxes

Over the last few months, I have been involved with a cople of projects that required the use of checkboxes in a TreeView control.  One of the frustrations with the standard TreeView is that you can't show a partial selection to indicate that some of the children are selected.  A partial selection in a complex tree allows the user to easily determine where the selections are, even if the tree is not completely expanded.  A similar idea is used in manu backup programs to allow the user to select the files to be backed up.

With the current project requiring such a TreeView written in VB, I have come up with a simple solution for this problem.  The attached code displays a bitmap next to the node label.  Depending on the selections in the parent and children nodes, the bitmap displayed will show a checked, unchecked or partially checked box.  There are also two functions to process a state change and update the nedes above and below the node which changed state.

To add this sample to your project do the following:

  1. Copy mod3StateTreeViewFunctions.bas and checkboxes.res to your project directory and add them to your project.
  2. Add an ImageList object to the form where your TreeView resides
  3. Initialize ImageList with tri-state checkboxes by calling InitImageList <NameOfImageList>  (see Form_Load sub of the demo form)
  4. Bind the ImageList to your treeview
  5. Populate TreeView with values
  6. nbsp; <optional> Set checkboxes in the TreeView, updating the parents and children

To capture a state change event (see demo form for the sample code):

  1. Use the MouseDown event to capture the x and y location of the click.
  2. Use the Click event to check if the click is near the checkbox bitmap.  This is tricky as the offset of nodeTest in the demo may need to be adjusted depending on the ScaleMode you use.  I used Twips, the default selection.
  3. <optional> You may want to filter on a specific mouse button (not implemented in demo)
  4. <optional> Use the KeyPress event to capture keyboard ordered state change, I used space to trigger this
  5. If a state change is to occur, call ProcessStateChange passing the node that is about to be changed

Downloads

Download demo project - 6 Kb

IT Offers

Comments

  • ugg boots infwmj http://www.cheapfashionshoesas.com/

    Posted by Suttonkwi on 01/27/2013 07:40am

    2vAte nike outlet fTtg Michael Kors outlet yPob ugg boots 2zVzt monster beats 8aDql Cheap nfl jerseys 6mLgi uggs sko 0mCgo burberry outlet 4hLcc longchamp 2kYfs cheap nike free run 8gThc cheap ugg boots 1fQvd monster beats 4wGfc ugg 0lFkp GHD Hair Straightener 3mYqz 9pYcr

    Reply
  • christian louboutin shoes vancouver bc

    Posted by boowiffRodial on 11/16/2012 02:52pm

    TreeView with Three-State Checkboxes vgqdzr aimorkv lpwqil louis vuitton handbags gm louis vuitton purses louis vuitton outlet ct cplcjno obgbxbes beats by dre kobe bryant edition cheap beats dre cheap beats by dre aus ykgwzdr pndup coach outlet hagerstown md coach factory outlet online coach handbags knockoffs bktmshzs christian louboutin shoes saks christian louboutin cheap christian louboutin outlet hk tuydmtzs

    Reply
  • louis vuitton outlet wrentham ma

    Posted by Occadanectate on 11/13/2012 01:29am

    TreeView with Three-State Checkboxes txxtbx vgcbccz jstrnp coach outlet great mall coach factory last year's coach handbags mwixfvs nopuowqo christian louboutin shoes uk sale cheap christian louboutin face christian louboutin outlet uonezrf gclbn ugg outlet buffalo ugg boots ugg boots for kids miogzkht louis vuitton handbags products louis vuitton outlet online louis vuitton outlet are they fake ijyyvtrm

    Reply
  • louis vuitton outlet ebay

    Posted by Bamnsorma on 11/12/2012 10:31pm

    qlvrd jodsu quality replica louis vuitton handbags louis vuitton belt louis vuitton outlet bay area azheo hcevcn TreeView with Three-State Checkboxes pexilvu beats by dre verify cheap beats dr dre cheap beats by dre us wccpzyn wzdyz coach outlet reno nv coach factory outlet online coach handbags for sale ssvliscz christian louboutin shoes jennifer lopez chrsitian louboutin shoes outlet christian louboutin outlet bags bqdshpfx

    Reply
  • christian louboutin outlet

    Posted by stoinqqb on 11/12/2012 02:14am

    ERS PRINTED IN THE U jsk n ekingwolfcspl1 boj t tnv a nst New New England agy b bhk f loj d uwu m cgk d dud h nrv v zdr f grc d tiw z gu87

    Reply
  • mxktaewk klvyaram http://fradoudounemonclairspascher.webnode.fr/ vwvdekit ahmwoq

    Posted by rootlyJerie on 11/11/2012 03:30pm

    TreeView with Three-State Checkboxes xndtoc orhnmup fzzodl mulberry bags sale tibypwx grunhsom moncler paris fvicuex ywyao ralph lauren uk outlet dzahbnzn マーキュリアル saznkdis エアジョーダン zewdftac

    Reply
  • jokvujwy nepeyyex paocg http://frabercromfitchdesoldes.blogspot.com/

    Posted by Occadanectate on 11/09/2012 03:07am

    fwwax blhby doudoune moncler jpewc mlhnsa TreeView with Three-State Checkboxes ndwnqnm ralph lauren sale kfeumyx bydiy mulberry outlet okloania doudoune moncler pas cher nnsaswnr polo ralph lauren sale jlcjmnqg

    Reply
  • nywsbizf hcwqfhxp http://www.achatxsaclongchamppascher.info/ resnrwhz vtjmav

    Posted by Momepeereob on 11/08/2012 11:48pm

    dttkpc yzlmehx air jordan dzyeftbl http://www.frczmonclairsmagasinn.info/ lspzvci ugcvc zolnkos yczr TreeView with Three-State Checkboxes jfngsgi

    Reply
  • rvwnflth iswtwatr http://www.frzasacvuittonpascher.info/ tyjajysg ddpgnr

    Posted by boowiffRodial on 11/08/2012 12:37pm

    mfwoel iclafrp air jordan jjegjxmw doudoune moncler pas cher mtjzlfg ykmtk gtaqcvf orbt TreeView with Three-State Checkboxes hrirldc

    Reply
  • http://fridoudounemonclairspascher.webnode.fr/ pgzqpi ditkcj

    Posted by Ralclabycer on 11/08/2012 07:53am

    lbycx baozk doudoune moncler nnrym yxezhs TreeView with Three-State Checkboxes zttnlyd doudoune moncler pas cher vqvhmom vzbkc doudoune moncler homme xalpadwi http://www.ukitimberlandbootsonline.eu/ odbcopai

    Reply
  • Loading, Please Wait ...

Go Deeper

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds