TreeView Control - managing aftercheck event

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 4 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
JaimeBou
Posts: 27
Last visit: Wed Jan 31, 2024 8:52 am
Has voted: 1 time

TreeView Control - managing aftercheck event

Post by JaimeBou »

I have three treeview controls on a form and would like to manage the checkboxes.

So when a certain checkbox is checked, I would like to turn off others.

I have an event working, but when I add the second event, they both seem to step on each other.

I test them separately and for the most part they do what I need.

I basically iterate through the nodes to determine whats checked and then turn them off as needed.

I was not sure if there is a better strategy or perhaps this control is not the best one to use for what I am trying to accomplish?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: TreeView Control - managing aftercheck event

Post by jvierra »

On a TreeView connect just clear all buttons on the checking of one.

You will have to enumerate al nodes an clear them. The is only one event for the whole control so it all has to be done in that event.

You are having problems with this because it is not what the TreeView is designed to do. When this happens it makes coding more difficult.

I would use the beforeChecked and find all checked nodes and clear them the accept the check event.
User avatar
JaimeBou
Posts: 27
Last visit: Wed Jan 31, 2024 8:52 am
Has voted: 1 time

Re: TreeView Control - managing aftercheck event

Post by JaimeBou »

I tried the beforechecked but that didn't seem to work.

To me, it seemed to make things worse.

You mentioned that the treeview was not designed to work the way I wanted.

Can you suggest a better control? Should I just go with checkboxes? That just seems like more coding?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: TreeView Control - managing aftercheck event

Post by jvierra »

If you just want to select one from a list of items then use the CheckedListBox control. It is easier to use.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: TreeView Control - managing aftercheck event

Post by jvierra »

JaimeBou wrote: Mon Nov 18, 2019 10:28 am Can you suggest a better control? Should I just go with checkboxes? That just seems like more coding?
For what you are asking you need to use RadioButtons. This does the job with no coding. Only one of a group can be selected.
This topic is 4 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked