Practical - 3
Practical - 3
C# controls are located in the Toolbox of the development environment, and you
use them to create objects on a form with a simple series of mouse clicks and
dragging motions. A ComboBox displays a text box combined with a ListBox, which
enables the user to select items from the list or enter a new value
The user can type a value in the text field or click the button to display a drop down
list. You can add individual objects with the Add method. You can delete items with
the Remove method or clear the entire list with the Clear method
comboBox1.Items.Add("A");
comboBox1.Items.Add("B");
comboBox1.Items.Add("C");
//OR
this.comboBox1.Items.Add("A");
this.comboBox1.Items.Insert(0, "B");
this.comboBox1.Items.Insert(1, "C");
this.comboBox1.Items.Insert(2, "D");
//step no-5
this.comboBox2.Items.Add("Week");
this.comboBox2.Items.Add("Month");
}
private void button1_Click(object sender, EventArgs e)
{
//step no-3: this code will prevent empty space
if (this.textBox1.Text != "")
{
//Second step
// if TextBox is empty, then space will be added to
ComboBox after every click of Add button
this.comboBox1.Items.Add(this.textBox1.Text);
this.textBox1.Text = "";
this.textBox1.Focus();
}
}
comboBox1.Items.Clear();
if (this.comboBox2.SelectedItem == "Week")
// if (comboBox2.SelectedItem.Equals ("week") )
{
this.comboBox1.Items.Add("Sunday");
this.comboBox1.Items.Add("Monday");
this.comboBox1.Items.Add("Tuesday");
this.comboBox1.Items.Add("Wednesday");
this.comboBox1.Items.Add("Thursday");
this.comboBox1.Items.Add("Friday");
}
else if(comboBox2.SelectedItem =="Month")
// else if (comboBox2.SelectedItem.Equals ("Month") )
{
this.comboBox1.Items.Add ("January");
this.comboBox1.Items.Add ("February");
this.comboBox1.Items.Add ("March");
this.comboBox1.Items.Add ("April");
this.comboBox1.Items.Add ("May");
} }
-------------------------------------------------------------------------------------------------------------------------------