Red
Red

Reputation: 35

Selected value of a wpf combobox isn't displayed on combobox

When I select any item of the combobox below, it doesn't get displayed on the combobox. The combobox is always blank even though its list of items is populated and allows selection of its items.

I looked it up and it looks like everything I did so far is the way it should be, but obviously something is wrong!

<ComboBox Margin="0,61,32,0" Width="100" Height="26" HorizontalAlignment="Right" x:Name="ExportComboBox">
                    <ComboBoxItem Width="100">
                        <StackPanel Orientation="Horizontal">
                            <Image Height="24" Source="Images/Word.png" Width="24" ToolTip="Word - .doc" />
                            <TextBlock Text=" Word" />
                        </StackPanel>
                    </ComboBoxItem>
                    <ComboBoxItem Width="100">
                        <StackPanel Orientation="Horizontal">
                            <Image Height="24" Source="Images/Excel.png" Width="24" ToolTip="Excel - .xls"/>
                            <TextBlock Text=" Excel" />
                        </StackPanel>
                    </ComboBoxItem>
                    <ComboBoxItem Width="100">
                        <StackPanel Orientation="Horizontal">
                            <Image Height="24" Source="Images/Txt.png" Width="24" ToolTip="Text - .txt" />
                            <TextBlock Text=" Text File" />
                        </StackPanel>
                    </ComboBoxItem>
                </ComboBox>

Any help will be very much appreciated, R

Upvotes: 0

Views: 321

Answers (1)

Terkel
Terkel

Reputation: 1575

Set the SelectedIndex property of the ComboBox to 0 and the first value will be selected when the ComboBox is loaded.

<ComboBox SelectedIndex="0" Margin="0,61,32,0" Width="100" Height="26" HorizontalAlignment="Right" x:Name="ExportComboBox">

Upvotes: 2

Related Questions