Why the databinding fails in ListView (WPF) ?
- by Ashish Ashu
I have a ListView of which ItemSource is set to my Custom Collection.
I have defined a GridView CellTemplate that contains a combo box as below :
           <ListView
            MaxWidth="850"                
            Grid.Row="1"
            SelectedItem="{Binding Path = SelectedCondition}"
            ItemsSource="{Binding Path = Conditions}"                 
            FontWeight="Normal"
            FontSize="11"                                
            Name="listview">
            <ListView.View>
                <GridView>
                    <GridViewColumn                           
                        Width="175"
                        Header="Type">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <ComboBox                                       
                                    Style="{x:Null}"
                                    x:Name="TypeCmbox"
                                    Height="Auto"
                                    Width="150"
                                    SelectedValuePath="Key"
                                    DisplayMemberPath="Value"    
                                    SelectedItem="{Binding Path = MyType}"
                                    ItemsSource="{Binding Path = MyTypes}"
                                    HorizontalAlignment="Center" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
              </ListView>
My Custom collection is the ObservableCollection.
I have a two buttons - Move Up and Move Down on top of the listview control . When user clicks on the Move Up or Move Down button I call MoveUp and MoveDown methods of Observable Collection.
But when I Move Up and Move Down the rows then the Selected Index of a combo box is -1.
I have ensured that selectedItem is not equal to null when performing Move Up and Move Down commands.
Please Help!!