Is it possible to make a button not clickable and just make it clickable when a textbox was filled out, radio button was ticked, checkbox and combo box item was selected?(it needs to be all done before making the button clickable) I already made the button unclickable but I need to make it clickable after filling out informations. Please help, thank you
-
1Use the property Enable = true/false to enable and disable.jdweng– jdweng2022-02-21 11:23:56 +00:00Commented Feb 21, 2022 at 11:23
-
I've tried that. But I need to get the textboxes, radiobuttons, combo boxes, and check boxes to be filled out. If this will be all true then that's the time that the button will be clickable.MULTI FANDOM– MULTI FANDOM2022-02-21 11:31:28 +00:00Commented Feb 21, 2022 at 11:31
3 Answers
One easy solution might be
Disable your button on start up
button1.Enabled=falseAdd events to your textbox etc. like
TextChangedand with the following code.if (!textBox1.Text.Equals(string.Empty) && checkBox1.Checked && comboBox1.SelectedItem != null) { button1.Enabled = true; } else { button1.Enabled = true; }
That might work for your case here
2 Comments
Since your question at this time does not contain code, I will refrain from adding code to the answer and offer you pseudocode to provide one of many possible solutions to this problem.
private void Ev_DoCheckEnableButton(object sender, EventArgs e)
{
//check here if textbox is filled, if radio button is ticked, if checkboed is checked and if combobox is selected
//if checks passed set the button to enabled
//if not passed then set it to disabled
}
Now for each control you want to check add a listener for the appropriate Event to Ev_DoCheckEnableButton and voila.
Comments
First put btnClickable to enable = false, then
basically you need to check if everything is as you need it to be, if it is as you wish, button is being enabled back.
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if(cb1.Checked==true && tbText.Text!=null && rb1.Checked==true)
{
btnClickable.Enabled = true;
}
}
Note: This is an example where we use ComboBox - SelectionChanged method, because you wrote it last in the ln the question, so i assumed it goes last.
If, for example you want to put checkbox as the last item, just activate Click event on it, and change terms in if(). (ComboBox1.SelectedItem==null instead of cb1.Checked==true))