简体   繁体   中英

C# Treeview creating child node depending on users Parent node

OK do I've been messing around with the treeview in C# , and I'm stuck trying to do something. I created a program that added classes( actual classes, as in school classes not program wise) based on what the user says, that worked fine. But now I want the user to be able to put a student within that class or any class they want. I have one tree view and 2 text boxes one to create a class and one to put a student in the class. Again I want the user to put a student within a class so a child node.

Ex.The user created a class called History 1020, then then they want to put a student in that class so they enter a name like Amy or whatever, I want the name Amy to be under the History 1020 node

I am not sure where you are held up. The logic is fairly simple:

  • Get the selected item in the treeview, which would be the "class."
  • Add a child node to it as the student.

You just have to make sure the selected item is a "class." You could use a prefix on the name and check for that. Ex. Class_Chemistry, Class_Math, etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM