This code shows how we can use combobox in our winforms application using c#.
public partial class frmComboBox_Demo : Form
{
public frmComboBox_Demo()
{
InitializeComponent();
comboBox1.Items.Add("Item 4");
comboBox1.Items.Add("Item 5");
comboBox1.Items.Add("Item 6");
comboBox1.SelectedIndex = 2;
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("Selected text of combobox is: " + comboBox1.SelectedText);
MessageBox.Show("Text of combobox is: " + comboBox1.Text);
}
private void button2_Click(object sender, EventArgs e)
{
comboBox1.Focus();
MessageBox.Show("Selected text of combobox is: " + comboBox1.SelectedText);
MessageBox.Show("Text of combobox is: " + comboBox1.Text);
}
}
No comments:
Post a Comment