Reputation: 390
I have a ComboBox in editable mode in my wpf application and I would like to know what would be the best way to get its Items string values for use. I tried moviecomboBox.Items.CurrentItem.ToString(), but it doesn't work.
Edit: Here is a part of my xaml code:
<ComboBox DisplayMemberPath="Movie" Grid.Column="1" Height="23" HorizontalAlignment="Left" ItemsSource="{Binding}" Margin="9,4,0,4" Name="movieComboBox" VerticalAlignment="Center" Width="120" IsEditable="True">
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel />
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
</ComboBox>
And I would like to be able to use the Items values in xaml.cs file.
Upvotes: 0
Views: 1158
Reputation: 390
Thanks for the answers the solution was in the end as simple as movieComboBox.Text.
Upvotes: 0
Reputation: 27055
Try using the SelectedItem
property:
moviecomboBox.SelectedItem != null ? moviecomboBox.SelectedItem.ToString() : null;
Upvotes: 1
Reputation: 693
Trying using SelectedItem instead of CurrentItem.
moviecomboBox.Items.SelectedItem.ToString()
Upvotes: 0