Binding ComboBox to a Listbox, Listview or Datagridview ... VS 2012 Store App RRS feed

  • Question

  • Hi

    Could anyone point me to an example of using a combobox to display/edit a value on a row in a Listbox, Listview or Datagridview ... I am having the same problem doing it on all of those controls.

    For the Listview case I have a Listview populated in the C# code from a list of an object with 3 attributes inventoryref, address1, postcode.

    I can display the 3 attributes in textblocks on the Listbox with the following XAML


    <ListView x:Name="ListView1" Margin="39,23,877,40" Grid.Row="1"  >
            <DataTemplate >
                <Grid  >
                    <StackPanel Orientation="Horizontal" VerticalAlignment="Top" Margin="10,0,0,0" >
                        <TextBlock Text="{Binding inventoryRef}" Style="{StaticResource BodyTextStyle}" Margin="10,0,0,0" />
                        <TextBlock Text="{Binding address1}" Style="{StaticResource BodyTextStyle}" Margin="10,0,0,0" />
                        <TextBlock Text="{Binding postcode}" Style="{StaticResource BodyTextStyle}" Margin="10,0,0,0" />

    That works fine but if I can't work out what to do if if I want to display the column inventoryRef as a combobox which is populated from a CollectionViewSource

    I have tried various combinations for DisplayMemberPath, SelectedValue etc eg:

    <ComboBox  ItemsSource="{Binding Source={StaticResource refViewSource}}" 
                SelectedValue="{ Binding Path=inventoryRef}" 
                Margin="10,0,0,0" >

    but it never works.

    The combobox populates correctly from the CollectionViewSource (refViewSource) but it doesn't take the value of the inventoryRef in the row it is on and if you select a value in the combobox on one row it will change the combobox on all rows but not actually set the value in any of the Listview rows.


    • Edited by ForestRich Wednesday, October 23, 2013 10:50 AM
    • Moved by Barry Wang Friday, October 25, 2013 3:13 AM
    Wednesday, October 23, 2013 10:49 AM

All replies

  • Hi ForestRich,

    Welcome to the MSDN forum.

    Since your case is Store App related I'll help you move it.


    Barry Wang
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, October 25, 2013 3:13 AM
  • Hi Forest,

    Try the following code for your combobox, more information about Windows Store app Binding can be found http://msdn.microsoft.com/en-us/library/windows/apps/hh464965.aspx:

    <ComboBox  ItemsSource="{Binding Source={StaticResource refViewSource}}" 
                SelectedItem="{Binding inventoryRef}" 
                Margin="10,0,0,0" >

    Best Regards,


    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Friday, October 25, 2013 10:15 AM
  • Thanks James but that code does not work either.

    As before the combo box is populated correctly but it does not select the appropriate item in the combo box according to the value of "inventoryref" in the Listview row and if the user selects a combo box item on one listview row, the combo boxes on all rows also change to select that item.

    I am trying to get the same functionality that you would have in  desktop C# app by using a


    Thursday, October 31, 2013 10:08 AM