Export (0) Print
Expand All

How to: Create a ComboBox

.NET Framework 3.0

In the following example, the ComboBox contains three items. The control is in its collapsed position, which is the default state, until the user clicks the Button on the right side of the control.

Example

<ComboBox Text="Is not open">
    <ComboBoxItem MouseMove="OnHover" Name="cbi1">Item1</ComboBoxItem>
    <ComboBoxItem MouseMove="OnHover" Name="cbi2">Item2</ComboBoxItem>
    <ComboBoxItem MouseMove="OnHover" Name="cbi3">Item3</ComboBoxItem>
</ComboBox>

cbox = new ComboBox();
cbox.Background = Brushes.LightBlue;
cboxitem = new ComboBoxItem();
cboxitem.Content = "Created with C#";
cbox.Items.Add(cboxitem);
cboxitem2 = new ComboBoxItem();
cboxitem2.Content = "Item 2";
cbox.Items.Add(cboxitem2);
cboxitem3 = new ComboBoxItem();
cboxitem3.Content = "Item 3";
cbox.Items.Add(cboxitem3);

cv2.Children.Add(cbox);

For the complete sample, see ComboBox Sample.

See Also

Community Additions

ADD
Show:
© 2015 Microsoft