CheckBox
When it is checked textbox will display “checked”. If it is unchecked textbox will display “aaa”
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
textBox1.Text = “checked”;
}
else
{
textBox1.Text = “aaa”;
}
}
CheckBoxList is filling with database
Adding connectionString in App.config file
</configSections>
<appSettings>
<add key=”ConnectionString” value=”Persist Security Info=False;Data Source=lokesh;Initial Catalog=winForms;User ID=sa;Password=xyz;” />
</appSettings>
private void checkbox_Load(object sender, EventArgs e)
{
//Calling app.config connectionString
SqlConnection objConn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
SqlCommand objCmd = new SqlCommand(”select *from tblCategory“, objConn);
DataSet objDs = new DataSet();
SqlDataAdapter objDa = new SqlDataAdapter(objCmd);
objConn.Open();
objDa.Fill(objDs);
objCmd.ExecuteNonQuery();
int count = objDs.Tables[0].Rows.Count;
for (int i = 0; i <= count-1; i++)
{
checkedListBox1.Items.Add(objDs.Tables[0].Rows[i]["Category"].ToString());
}
objConn.Close();
}
CheckBox can be checked at runtime
checkBox1.Checked = true;