How to link specific parent node of a TreeView to a specific file (vb.net/c#) -


i have treeview has n numeber of parent nodes, each equal number of child nodes, following example (city 1, 2, ... parent nodes; , child nodes house, hotel, shop, bank, school);

city1
- house
- hotel
- shop
- bank
- school
city2
- house
- hotel
- shop
- bank
- school
city3
- house
- hotel
- shop
- bank
- school

now, do operation based on following rules:

if child under particular parent node, city1, checked) checked, parent node state checked well. thus, can read information city1 file, file_index_1. since file_index_1 located, doesn't matter if child node same parent node checked. need @ least 1 child node checked check parent node , use corresponding file

if city2 (or of child) checked, file_index_2 invoked

if cityn (or of child) checked, file_index_n invoked

if both parent nodes checked (because minimum of 1 child node checked under each parent node), file_index_associated parentnode child node being checked.

if instance city1 not checked (because no child nod checked under it), file-index_1 not used.

if no child node checked under parent nodes, no file invoked.

in aftercheck event, can index of checked parent node following code:

dim nodeindex integer = 0

    k integer = 0 numberofparentnodes         if e.node.text = "specific parentnode name, eg. city1"             nodeindex = e.node.index               'call file same index parentnode index             'but how if childnode checked if parentnode not checked??             'and how index of parent node of child being checked         end if     next 

but have difficulties relate child.checked => parent.checked. hope intention understandable. can how that?

hopefully starting place code you're looking :

private sub treeviewbuilderbutton_click(sender system.object, e system.eventargs) handles treeviewbuilderbutton.click      dim nd treenode = testtreeview.nodes.add("c1", "city1")     addchildren(nd)     nd = testtreeview.nodes.add("c2", "city2")     addchildren(nd)     nd = testtreeview.nodes.add("c3", "city3")     addchildren(nd)      testtreeview.expandall()  end sub  private sub addchildren(nd treenode)      nd.nodes.add(string.concat(nd.name, "_house"), "house")     nd.nodes.add(string.concat(nd.name, "_hotel"), "hotel")     nd.nodes.add(string.concat(nd.name, "_shop"), "shop")     nd.nodes.add(string.concat(nd.name, "_bank"), "bank")     nd.nodes.add(string.concat(nd.name, "_school"), "school") end sub  private sub testtreeview_aftercheck(sender object, e system.windows.forms.treevieweventargs) handles testtreeview.aftercheck     try          if (e.action <> treeviewaction.unknown)             dim nd treenode = directcast(e.node, treenode)              nd.parent.checked = anychildchecked(nd.parent)              debug.print(string.concat("node: ", nd.text, " node name: ", nd.name, " parent: ", nd.parent.text, " parent name:", nd.parent.name))         end if      catch ex exception         messagebox.show(string.concat("an error occurred: ", ex.message))     end try end sub  private function anychildchecked(nd treenode) boolean      each ndchild treenode in nd.nodes         if ndchild.checked             return true         end if     next      return false  end function 

as example, checked city 2 hotel , city1 bank debug output follows:

node: hotel node name: c2_hotel parent: city2 parent name:c2
node: bank node name: c1_bank parent: city1 parent name:c1


Comments

Popular posts from this blog

android - Pass an Serializable object in AIDL -

How to provide Authorization & Authentication using Asp.net, C#? -

How to use Authorization & Authentication in Asp.net, C#? -