Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checked?

Status
Not open for further replies.

RascaPR

Technical User
Oct 27, 2007
26
US
How can I have a checkbox automatically be in a checked state when the form loads?

Sounds so simple but it's eating me up!
 
Look at the Properties window of CheckBox for "Checked"

________________________________________________________
Zameer Abdulla
Help to find Missing people
 
Hello Abdulla,

I should have explained myself a bit better. :)

I want it to appear checked with an IF statement. For example:

Code:
        private void Login_Load(object sender, EventArgs e)
        {
            if (exists == true)
            {
               CODE HERE TO MAKE CHECKBOX APPEAR AS CHECKED
            }
        }
 
Checked is also a property of a checkbox in the designer properties window. if you owant the checkbox always to be checked on startup set it there.

also, don't ever test booleans against true or false, it makes you look stupid. using

Code:
if ( exists )
{
 // ...
}

is not only more concise, it means you'll never code something like this

Code:
if ( exists = true )
{
 // ...
}

which sets exists to true and then does the conditional code whatever the previous value of the exists variable.

and no, putting the constant as the lvalue isn't acceptable either.

hth,

mr s. <;)

 
Ok, but how would I code it so that the check box is CHECKED, if the conditional is true? The reason why I do not make it checked via the designer properties window, is because this would make it checked all the time and I don't want that. I only want it to appear checked, IF the conditional is met.
 
Code:
private void Login_Load(object sender, EventArgs e)
{
 if ( exists )
 {
  checkBox1.Checked = true;
 }
}


mr s. <;)

 
or you could also do what JurkMonkey suggested

Code:
private void Login_Load(object sender, EventArgs e)
{
 
  checkBox1.Checked = exists ;

}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top