enable button if checkbox state changes

Nucleus

Active member
Joined
May 24, 2005
Messages
30
Programming Experience
Beginner
I know how enable a button when the state of a checkbox is enabled or disabled.

But in my case I want to enable the button simply when the state of the checkbox is changed.

It doesn’t matter in which state the checkbox is. It can be enabled or disabled when the form opens, but when the state changes I want to enable the button.

How can I do that?
 
Just as always, you handle the appropriate event. Do you really mean enabled and disabled in relation to the CheckBox? If so then you would handle the EnabledChanged event. I'm guessing that you actually mean checked and unchecked though, in which case you would handle the CheckedChanged event.
 
ok, please bare with me as I'm only a few days in this vb stuff and I'm still trying to understand the logic behind it.

This, works great.

VB.NET:
Private Sub ApacheModActions_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ApacheModActions.CheckedChanged

    MessageBox.Show("CheckBox is now " + ApacheModActions.Checked.ToString)

End Sub

Every time I select and deselect the checkbox, the messagebox appears and informs me of the event and the state of the checkbox.

How do I apply the same logic with a button, to enable it everytime a checkbox is selected or deselected?
 
Button1.Enabled = True

But how will the button know when to enable itself? if the state of the checkbox changes. Right?
But how will the button know that the state of the checkbox has changed?

I didnt get it :culpability:

I think I just answered my own question :)

Thanks for asking the right question. This worked.

VB.NET:
    Private Sub ApacheModActions_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ApacheModActions.CheckedChanged

        ApacheSaveButton.Enabled = True

    End Sub
 
Thanks for asking the right question.
That is always my preferred approach. Many, many times people already have the answer but they just don;t know the right question. I call it the "Jeopardy method". ;)
 
Sorry to be bringing this up again, but instead of checkboxes, I am now using a CheckedListBox. So now I cannot go on each checkbox and tell it to enable the button if the checkbox state changes. Now I need to somehow check all the items in the CheckedListBox and find out if any one of them changed their state, and then enable the button. Ideas?
 
The CheckedListBox has an ItemCheck event, so you can use it in just about the same way as the CheckedChanged of the individual CheckBoxes. The event will tell you which item is changing and whether it is being checked or unchecked.
 
Back
Top