locked
WPF ListView with a ComboBox RRS feed

  • Question

  • We have ListView with ComboBox. I am binding data to list on the button click. And i want to show combobox with  selected value . When we set IsSynchronizedWithCurrentItem="True" then its updating all value of combobox but when we set IsSynchronizedWithCurrentItem="False" then combo box not showing selected value. Why?  I am using mvvm Model for bind data for both list view and combobox not  hard coded.If  you have solution then please share with me.

     <GridViewColumn Header="Part ID">
                                                            <GridViewColumn.CellTemplate>
                                                                <DataTemplate>
                                                                    <ComboBox x:Name="PartIdListViewRadComboBox"   IsEditable="True"  Width="105" Height="30" Margin="4,4,4,4" VerticalAlignment="Center"  StaysOpenOnEdit="False"  
                                             IsSynchronizedWithCurrentItem="False" SelectedValue="{Binding Path=ProductID}"
                                             DisplayMemberPath="PartID"  HorizontalAlignment="Left"   ItemsSource="{ Binding RelativeSource=
                                        					{RelativeSource FindAncestor,AncestorType={x:Type ListView}},Path=DataContext.ProductModel.ListViewComboboxProductListCollection}"   
                                                                     IsTextSearchEnabled="True" >
                                                                        <!--<ie:Interaction.Triggers>
                                                                            <ie:EventTrigger EventName="SelectionChanged">
                                                                                --><!--<si:CallMethodAction MethodName="SelectionChanged" TargetObject="{Binding}" />--><!--
                                                                                <ie:InvokeCommandAction Command="{Binding RelativeSource=
                                        					{RelativeSource FindAncestor,AncestorType={x:Type ListView}},Path=DataContext.PartIdComboboxChangedComand}" CommandParameter="{Binding ElementName=PartIdListViewRadComboBox}" />
                                                                            </ie:EventTrigger>
                                                                        </ie:Interaction.Triggers>-->
                                                                    </ComboBox>
                                                                </DataTemplate>
                                                            </GridViewColumn.CellTemplate>



    Friday, March 18, 2016 6:33 AM

Answers

  • Please remember to close your previous threads by marking helpful posts as answer before starting a new thread.

    >>When we set IsSynchronizedWithCurrentItem="True" then its updating all value of combobox but when we set IsSynchronizedWithCurrentItem="False" then combo box not showing selected value. Why?

    Make sure that the ProductID property of the data object in the ItemsSource of the ListView has a value that exists in the ListViewComboboxProductListCollection collection. If the collection contains Product objects rather than product ids, you should set the SelectedValuePath property of the ComboBox to "ProductID" or whatever the property name that corresponds to the selected value of the ComboBox is:

    <ComboBox x:Name="PartIdListViewRadComboBox"   IsEditable="True"  Width="105" Height="30" Margin="4,4,4,4" VerticalAlignment="Center"  StaysOpenOnEdit="False"  
                                             IsSynchronizedWithCurrentItem="False" SelectedValue="{Binding Path=ProductID}"
                                             SelectedValuePath="ProductID"
                                             DisplayMemberPath="PartID"  HorizontalAlignment="Left"   ItemsSource="{ Binding RelativeSource=
                                             {RelativeSource FindAncestor,AncestorType={x:Type ListView}},Path=DataContext.ProductModel.ListViewComboboxProductListCollection}"   
                                                                     IsTextSearchEnabled="True" >
    ...

    The value of the SelectedValuePath property is supposed to be a name of a property of an object in the ListViewComboboxProductListCollection.

    Hope that helps.

    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.


    Saturday, March 19, 2016 12:01 PM

All replies

  • Please remember to close your previous threads by marking helpful posts as answer before starting a new thread.

    >>When we set IsSynchronizedWithCurrentItem="True" then its updating all value of combobox but when we set IsSynchronizedWithCurrentItem="False" then combo box not showing selected value. Why?

    Make sure that the ProductID property of the data object in the ItemsSource of the ListView has a value that exists in the ListViewComboboxProductListCollection collection. If the collection contains Product objects rather than product ids, you should set the SelectedValuePath property of the ComboBox to "ProductID" or whatever the property name that corresponds to the selected value of the ComboBox is:

    <ComboBox x:Name="PartIdListViewRadComboBox"   IsEditable="True"  Width="105" Height="30" Margin="4,4,4,4" VerticalAlignment="Center"  StaysOpenOnEdit="False"  
                                             IsSynchronizedWithCurrentItem="False" SelectedValue="{Binding Path=ProductID}"
                                             SelectedValuePath="ProductID"
                                             DisplayMemberPath="PartID"  HorizontalAlignment="Left"   ItemsSource="{ Binding RelativeSource=
                                             {RelativeSource FindAncestor,AncestorType={x:Type ListView}},Path=DataContext.ProductModel.ListViewComboboxProductListCollection}"   
                                                                     IsTextSearchEnabled="True" >
    ...

    The value of the SelectedValuePath property is supposed to be a name of a property of an object in the ListViewComboboxProductListCollection.

    Hope that helps.

    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.


    Saturday, March 19, 2016 12:01 PM
  • I don't follow what issue you want help with.

    When we set IsSynchronizedWithCurrentItem="True" then its updating all value of combobox but when we set IsSynchronizedWithCurrentItem="False" then combo box not showing selected value. Why?

    What that setting does is select the current item of a collection. You can read more about that here:

    http://social.technet.microsoft.com/wiki/contents/articles/26673.wpf-collectionview-tips.aspx#Programmatic_Selection_of_Record

    Which brings me to one of the problems with the question: no code.

    I guess maybe you're making an item current.

    Whether that's a good idea is guesswork without more explanation of intent and code.

    Maybe you'd do better binding selecteditem to a viewmodel property so you could set that to the object you want selected.

    If  you have solution then please share with me.

    That might be easier if you'd explained what problem you want a solution to. The one question you've asked doesn't really seem to be much of a problem.


    Hope that helps.

    Technet articles: WPF: Layout Lab; All my Technet Articles

    Saturday, March 19, 2016 3:41 PM