Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wpf comboBox selectedIndex=0 is not working

Tags:

combobox

wpf

.xaml

<ComboBox Grid.Row="0" Grid.Column="1" x:Name="cbx_srchResOrg" HorizontalAlignment="Stretch" Style="{DynamicResource ComboBoxStyle}"
                      ItemsSource="{Binding InfoCombo}" SelectedIndex="0" DisplayMemberPath="Dis_name" SelectedValuePath="Hide_id" SelectedItem="{Binding SelectInfo}"/>

Here is a part of my source code. Why 'SelectedIndex=0' is not working? I want to select [0] value to default at first time, but it just empty box at run time. There are no errors except it. How can I fix it?

like image 730
parfum Avatar asked Mar 28 '17 05:03

parfum


Video Answer


1 Answers

As Hej said, you have binded the SelectedItem with a property in your view model which was null.

You can fix this by assigning the SelectedItem in your Viewmodel constructor

Public MyViewModel()
{
    SelectInfo = InfoCombo[0];
}
like image 99
Gopichandar Avatar answered Sep 28 '22 16:09

Gopichandar