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.
Post Reply
User avatar
JaimeBou
Posts: 14
Joined: Fri Feb 09, 2018 9:57 am

TreeView Control - managing aftercheck event

Post by JaimeBou » Mon Nov 18, 2019 9:24 am

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: 14000
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: TreeView Control - managing aftercheck event

Post by jvierra » Mon Nov 18, 2019 10:26 am

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: 14
Joined: Fri Feb 09, 2018 9:57 am

Re: TreeView Control - managing aftercheck event

Post by JaimeBou » Mon Nov 18, 2019 11:28 am

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: 14000
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: TreeView Control - managing aftercheck event

Post by jvierra » Mon Nov 18, 2019 11:30 am

If you just want to select one from a list of items then use the CheckedListBox control. It is easier to use.

jvierra
Posts: 14000
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: TreeView Control - managing aftercheck event

Post by jvierra » Mon Nov 18, 2019 11:43 am

JaimeBou wrote:
Mon Nov 18, 2019 11: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.

Post Reply