I know that is a old post, but today i need this and i think i found a solution, so i want to share it. We can also use click event instead CheckedChange, so we can handler only event from user and change programmatically the value each time we want
Thanks. That will actually work.
I didn't know ToggleButton had a Click event because the Designer only generates "ToggleButton1_CheckedChange()" event. The help only shows a "CheckedChange(Checked As Boolean)" event and there is no mention of a Click event.
So if I put my user event code in ToggleButton1_Click it executes only if the user clicks on the button and won't get executed when the ToggleButton1.Checked = True gets executed located somewhere else in my code. Which is what I needed. Thanks.
Note: If the toggle button is clicked, the ToggleButton1_CheckChanged gets executed first then ToggleButton1_Click gets executed. So this one action executes 2 events. Strange but true. I'm not sure why the CheckChanged gets executed
before the Click event. For future purposes, I thought there might be some way if the Click event gets executed first it could (somehow) conditionally prevent the CheckChanged event from getting called, so the Checked value does not change under some conditions controlled by the Click event. That won't be possible because the events are executed in the wrong order. Even if it did execute in the correct order: Click then CheckChanged, I'm not sure what the Click event could do to prevent CheckChanged from executing and changing the Checked value.