{"id":1299,"date":"2015-01-14T17:50:26","date_gmt":"2015-01-14T17:50:26","guid":{"rendered":"https:\/\/ibex.tech\/visualcpp\/?p=1299"},"modified":"2022-02-17T06:24:03","modified_gmt":"2022-02-17T06:24:03","slug":"checkboxes","status":"publish","type":"post","link":"https:\/\/ibex.tech\/visualcpp\/tree-view\/checkboxes","title":{"rendered":"Checkboxes"},"content":{"rendered":"<h4>\nTurning On Checkboxes For A TreeView<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n\tMyTreeView-&gt;CheckBoxes = true;\r\n<\/code><\/pre>\n<h4>\nShowing Checkboxes only for certain nodes<br \/>\n<\/h4>\n<p>\nThis isn&#39;t&nbsp;a feature of TreeView, but can easily be created by using images &#8211; see below&#8230;\n<\/p>\n<h4>\nUsing images for tree view nodes (e.g. checkboxes only for some nodes)<br \/>\n<\/h4>\n<p>\nAdd an image list to your form. &nbsp;Set its&nbsp;ImageSize&nbsp;property to match the size of the images you will add. &nbsp;Assign it to the tree view:\n<\/p>\n<pre>\r\n<code>\r\n\tMyTreeView-&gt;ImageList = MyImageList;\r\n<\/code><\/pre>\n<p>\nTo set the image for a node (you need to&nbsp;do it for selected state also or the image will change when a node is clicked on):\n<\/p>\n<pre>\r\n<code>\r\n\tMyTreeNode-&gt;Nodes[0]-&gt;ImageIndex = 1;\r\n\tMyTreeNode-&gt;Nodes[0]-&gt;SelectedImageIndex = 1;\r\n<\/code><\/pre>\n<p>\nToggle the checked state when a node is clicked:\n<\/p>\n<pre>\r\n<code>\r\n\tprivate: System::Void MyTreeView_AfterSelect(System::Object^  sender, System::Windows::Forms::TreeViewEventArgs^  e)\r\n\t{\r\n\t\tif (MyTreeView-&gt;SelectedNode)\t\t\/\/Ensure a node is selected\r\n\t\t{\r\n\t\t\tif (MyTreeView-&gt;SelectedNode-&gt;Level == 1)\t\t\/\/0 = root level of any node, 1 1st child level, etc\r\n\t\t\t{\r\n\t\t\t\t\/\/Work out this nodes location within the TreeView\r\n\t\t\t\tint NodeIndex = e-&gt;Node-&gt;Index;\r\n\t\t\t\tTreeNode ^ParentTreeNode = e-&gt;Node-&gt;Parent;\r\n\t\t\t\tint ParentIndex = ParentTreeNode-&gt;Index;\r\n\r\n\t\t\t\t\/\/Toggle the checkbox image\r\n\t\t\t\tif (MyTreeView-&gt;SelectedNode-&gt;ImageIndex)\r\n\t\t\t\t{\r\n\t\t\t\t\tMyTreeView-&gt;SelectedNode-&gt;ImageIndex = 0;\r\n\t\t\t\t\tMyTreeView-&gt;SelectedNode-&gt;SelectedImageIndex = 0;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tMyTreeView-&gt;SelectedNode-&gt;ImageIndex = 1;\r\n\t\t\t\t\tMyTreeView-&gt;SelectedNode-&gt;SelectedImageIndex = 1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tMyTreeView-&gt;SelectedNode = nullptr;\r\n\t\t}\r\n\t}\r\n<\/code><\/pre>\n<p>\n&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Turning On Checkboxes For A TreeView MyTreeView-&gt;CheckBoxes = true; Showing Checkboxes only for certain nodes This isn&#39;t&nbsp;a feature of TreeView, but can easily be created by using images &#8211; see below&#8230; Using images for tree view nodes (e.g. checkboxes only for some nodes) Add an image list to your form. &nbsp;Set its&nbsp;ImageSize&nbsp;property to match the [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[112],"tags":[],"class_list":["post-1299","post","type-post","status-publish","format-standard","hentry","category-tree-view"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/1299","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/comments?post=1299"}],"version-history":[{"count":7,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/1299\/revisions"}],"predecessor-version":[{"id":1307,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/1299\/revisions\/1307"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/media?parent=1299"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/categories?post=1299"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/tags?post=1299"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}