ComboBox In WPF
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.
<ComboBox Name="ComboBox1" Width="200" Height="30"
VerticalAlignment="Top" HorizontalAlignment="Left"
Margin="10,10,0,0">
</ComboBox
Adding ComboBox Items and Event-
<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">TCS</ComboBoxItem>
<ComboBoxItem Background="SteelBlue" BorderBrush="Brown">Tech Mahindra</ComboBoxItem>
<ComboBoxItem Background="Violet" BorderBrush="Chartreuse">Birla Soft</ComboBoxItem>
<ComboBoxItem Background="YellowGreen" BorderBrush="Chocolate">AMDOCS</ComboBoxItem>
<ComboBoxItem Background="SteelBlue" BorderBrush="DimGray">Nagarro</ComboBoxItem>
</ComboBox>
Output
Code For Event In ComboBox-
private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
comboBox2.IsEnabled = true;
comboBox2.Items.Clear();
if (comboBox1.SelectedIndex == 0)
{
comboBox2.Items.Add("Java");
comboBox2.Items.Add(".Net");
comboBox2.Items.Add("PHP");
comboBox2.Items.Add("Mainframe");
}
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++");
}
}
No comments:
Post a Comment