GC87
GC87

Reputation: 390

wpf ComboBox and how to get values out of Items

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

Answers (3)

GC87
GC87

Reputation: 390

Thanks for the answers the solution was in the end as simple as movieComboBox.Text.

Upvotes: 0

Arcturus
Arcturus

Reputation: 27055

Try using the SelectedItem property:

moviecomboBox.SelectedItem != null ? moviecomboBox.SelectedItem.ToString() : null;

Upvotes: 1

Saghar
Saghar

Reputation: 693

Trying using SelectedItem instead of CurrentItem.

moviecomboBox.Items.SelectedItem.ToString()

Upvotes: 0

Related Questions