{"id":728,"date":"2008-05-23T11:10:10","date_gmt":"2008-05-23T11:10:10","guid":{"rendered":"http:\/\/6teen.ru\/?p=593"},"modified":"2008-05-23T11:10:10","modified_gmt":"2008-05-23T11:10:10","slug":"2091","status":"publish","type":"post","link":"http:\/\/pblog.ru\/lab\/?p=728","title":{"rendered":"\u041f\u043e\u0438\u0441\u043a Item&#8217;\u0430 \u0432 TreeView"},"content":{"rendered":"<p>\u041f\u043e\u0438\u0441\u043a Item&#8217;\u0430 \u0432 TreeView<br \/>\n<!--more--><\/p>\n<pre class=\"alt2\" style=\"margin:0px; padding:6px; border:1px inset; width:580px; height:320px; overflow:auto\"><div>\u041f\u043e\u0438\u0441\u043a Item'\u0430 \u0432 TreeView\n\n(how to find an item in a tree control via its label)\nthe \"tree view\" common control does not have any built-in method for searching the entire tree, or for selecting an item contained within the tree when given a specific item label. this article provides code that returns the location of any item in a tree when given a specific label to search for.\n\nthe getitembyname() function takes the window handle of the tree control, htreeitem, which points to the item in the tree to start searching and a string for which to search.\n\nunit unit1;\ninterface\nuses\nwindows, messages, sysutils, classes, graphics, controls, forms, dialogs,\nstdctrls, comctrls;\ntype\ntform1 = class(tform)\nbutton1: tbutton;\ntreeview1: ttreeview;\nprocedure button1click(sender: tobject);\nprivate\n{ private declarations }\npublic\n{ public declarations }\nend;\nvar\nform1: tform1;\n\nimplementation\n{$r *.dfm}\nuses  commctrl;\n\n\/\/ note: if you have items with more than 50 characters\n\/\/ of text, you'll need to increase this value.\nconst maxtextlen=50;\n\nfunction getitembyname(wnd : hwnd;  hitem : htreeitem; szitemname : lpctstr) : htreeitem ;\nvar  szbuffer: array [0..maxtextlen+1] of char;\nitem : ttvitem;\nhitemfound, hitemchild : htreeitem;\nbegin\n\/\/ if hitem is null, start search from root item.\nif (hitem = nil) then\nhitem := htreeitem(sendmessage(wnd, tvm_getnextitem, tvgn_root, 0));\nwhile (hitem <> nil) do\nbegin\nitem.hitem := hitem;\nitem.mask := tvif_text or tvif_children;\nitem.psztext := szbuffer;\nitem.cchtextmax := maxtextlen;\nsendmessage(wnd, tvm_getitem, 0, longint(@item));\n\/\/ did we find it?\nif (lstrcmp(szbuffer, szitemname) = 0) then\nbegin\nresult := hitem;\nexit;\nend;\n\/\/ check whether we have child items.\nif (item.cchildren > 0) then\nbegin\n\/\/ recursively traverse child items.\nhitemchild := htreeitem(sendmessage(wnd, tvm_getnextitem, tvgn_child, longint(hitem)));\nhitemfound := getitembyname(wnd, hitemchild, szitemname);\n\/\/ did we find it?\nif (hitemfound <> nil) then\nbegin\nresult :=  hitemfound;\nexit;\nend;\nend;\n\/\/ go to next sibling item.\nhitem := htreeitem(sendmessage(wnd, tvm_getnextitem, tvgn_next, lparam(hitem)));\nend;\n\/\/ not found.\nresult := nil;\nend;\n\nprocedure tform1.button1click(sender: tobject);\nvar  hitem : htreeitem;\nbegin\nhitem := getitembyname(treeview1.handle, nil, 'serge');\nif (hitem <> nil) then\nbegin\ntreeview1.setfocus;\nsendmessage(treeview1.handle, tvm_selectitem, tvgn_caret,  longint(hitem));\nend;\nend;\nend.\n<\/div><\/pre>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041f\u043e\u0438\u0441\u043a Item&#8217;\u0430 \u0432 TreeView<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[430,386],"tags":[1150,1924,285],"_links":{"self":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/posts\/728"}],"collection":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=728"}],"version-history":[{"count":0,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/posts\/728\/revisions"}],"wp:attachment":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=728"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=728"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=728"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}