Category: WinForm App

Nov 07 2009

Winform ProgressBar and Timer control

Add ProgressBar and TimerControl in Form

In Timer Tick event write this code

private void timer1_Tick(object sender, EventArgs e)

{

if (progressBar1.Value >= 200)

{

progressBar1.Value = 0;

return;

}

progressBar1.Value += 20;

}

}

Nov 07 2009

Winform checkedListBox

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;

Alibi3col theme by Themocracy