0

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

2
  • 1
    Use the property Enable = true/false to enable and disable. Commented 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. Commented Feb 21, 2022 at 11:31

3 Answers 3

1

One easy solution might be

  1. Disable your button on start up button1.Enabled=false

  2. Add events to your textbox etc. like TextChanged and 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

Sign up to request clarification or add additional context in comments.

2 Comments

I have many radio buttons, textboxes and checkboxes, is there anyways to code it lesser? They're group inside a groupbox
You can write a seperat function like 'ChekcIfButtonEnabled' and call it from every update event. That atleast should remove alot of doubled code.
0

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

0

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))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.