Category: Common Controls

Nov 07 2009

winforms ComboBox DataSource

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>


Winform ComboBox Databinding

private void ComboBox1_Load(object sender, EventArgs e)

{

SqlConnection objConn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);

SqlCommand objCmd = new SqlCommand(”select CategoryID,Category from tblCategory“, objConn);

DataSet objDataset= new DataSet();

SqlDataAdapter objDa = new SqlDataAdapter(objCmd);

objConn.Open();

objDa.Fill(objDataset);

comboBox1.DataSource = objDataset.Tables[0];

comboBox1.DisplayMember = “Category”;

//comboBox1.ValueMember = “CategoryID”;

comboBox1.ValueMember = “Category”; //Remember this

objConn.Close();

}

Winform ComboBox SelectionChanged Event

private void comboBox1_SelectionChangeCommitted(object sender, EventArgs e)

{

//Getting ComboBox Selected Value

string a = comboBox1.SelectedValue.ToString();

textBox1.Text = a;

}

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;

}

}

Alibi3col theme by Themocracy