Emma W. Emma W. - 1 month ago 10
C# Question

Add static and dynamic data to combobox wpf

I have a

combobox
and that intilized like so:

XAML

<ComboBox x:Name="cmbMarkOfWatch"
Grid.Column="0" Grid.Row="2"
Margin="1"
Width="230"
MaxHeight="20"
HorizontalAlignment="Left" />


C sharp

cmbMarkOfWatch.ItemsSource = obj.Clock.Select(w => w.mark).ToArray();
cmbMarkOfWatch.SelectedIndex = 0;


I want to add one static value
All
To the top of the
combobox
.
How I can do it?

Best regards

Answer Source

Try,

List<string> results = obj.Clock.Select(w => w.mark).ToList();
results.Insert(0, "All");
cmbMarkOfWatch.ItemsSource = resutls;
cmbMarkOfWatch.SelectedIndex = 0;