WPF Web Based

WPF Examples

WPF

WPF Projects

WPF Project

adplus-dvertising
ComboBox in WPF Web Based
Previous Home Next

A ComboBox control is an items control that works as a ListBox control but only one item from the collection is visible at a time and clicking on the ComboBox makes the collection visible and allows users to pick an item from the collection. Unlike a ListBox control, a ComboBox does not have multiple item selection. A ComboBox control is a combination of three controls A Button, a Popup, and a TextBox.

The Button control is used to show or hide available items and Popup control displays items and let user select one item from the list. The TextBox control then displays the selected item.

Syntax of Combobox in XAML File:

The ComboBox element represents a ComboBox control in XAML.

<ComboBox></ComboBox>

The Width and Height properties represent the width and the height of a ComboBox. The x:Name property represents the name of the control, which is a unique identifier of a control. The Margin property sets the location of a ComboBox on the parent control. The HorizontalAlignment and VerticalAlignment properties are used to set horizontal and vertical alignments.

The code creates a ComboBox control and sets the name, height, and width of a ComboBox control. The code also sets the vertical and horizontal alignment of the ComboBox and sets the margin.

 <ComboBox Name="ComboBox1" Width="200" Height="30"
 VerticalAlignment="Top" HorizontalAlignment="Left"
 Margin="10,10,0,0">
 </ComboBox>
ComboBox Items and Event-Adding
<ComboBox Height="25" Margin="147.5,106.25,163.75,0"
    Name="comboBox1" VerticalAlignment="Top" 
    SelectionChanged="comboBox1_SelectionChanged">
<ComboBoxItem Background="Tomato" BorderBrush="Cyan" >
   Infosis</ComboBoxItem>
<ComboBoxItem Background="SpringGreen" BorderBrush="Bisque">
   Microsoft</ComboBoxItem>
<ComboBoxItem Background="SteelBlue" BorderBrush="Brown">
   L & T Infotech</ComboBoxItem>
<ComboBoxItem Background="Violet" BorderBrush="Chartreuse">
   R4R tech soft</ComboBoxItem>
<ComboBoxItem Background="YellowGreen" BorderBrush="Chocolate">
   NIIT</ComboBoxItem>
<ComboBoxItem Background="SteelBlue" BorderBrush="DimGray">
   CSC</ComboBoxItem>
</ComboBox>
comboBox2.IsEnabled = true;
comboBox2.Items.Clear();
if (comboBox1.SelectedIndex  == 0)
{
comboBox2.Items.Add("Interview Question");
comboBox2.Items.Add("Java Interview Question");
comboBox2.Items.Add("PHP Interview Question");
comboBox2.Items.Add("PlaceMent paper");
}
else if (comboBox1.SelectedIndex == 1)
{
comboBox2.Items.Add("SAP");
comboBox2.Items.Add("ERP");
comboBox2.Items.Add("Networking");
comboBox2.Items.Add("C/C++");
}
else
{
comboBox2.Items.Add("Networking");
comboBox2.Items.Add("C/C++");
}
Adding and Deleting ComboBox Items at Run-time:

.CS Code:

private void button1_Click(object sender, RoutedEventArgs e)
{
comboBox1.Items.Add(textBox1.Text);
}
private void button2_Click(object sender, RoutedEventArgs e)
{
comboBox1.Items.RemoveAt(comboBox1.Items.IndexOf
	(comboBox1.SelectedItem));
 }
Previous Home Next
WPF Examples

WPF

WPF

WPF

WPF

WPF

WPF

WPF

WPF