Page 1 of 1

TreeView Control - managing aftercheck event

Posted: Mon Nov 18, 2019 9:24 am
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?

Re: TreeView Control - managing aftercheck event

Posted: Mon Nov 18, 2019 10:26 am
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.

Re: TreeView Control - managing aftercheck event

Posted: Mon Nov 18, 2019 11:28 am
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?

Re: TreeView Control - managing aftercheck event

Posted: Mon Nov 18, 2019 11:30 am
by jvierra
If you just want to select one from a list of items then use the CheckedListBox control. It is easier to use.

Re: TreeView Control - managing aftercheck event

Posted: Mon Nov 18, 2019 11:43 am
by jvierra
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.