views:

446

answers:

2

I have a ComboBox hosted in a ListView and I need changes in the CombBox to update the supporing class that the ListView is bound to.

Here is my DataTemplate

<DataTemplate x:Key="Category">
    <ComboBox IsSynchronizedWithCurrentItem="False" 
              Style="{StaticResource DropDown}" 
              ItemsSource="{Binding Source={StaticResource Categories}}"
              SelectedValuePath="Airport"
              SelectedValue="{Binding Path=Category}"
              />
    </DataTemplate>

This is the Listview. The ItemSource for the ListView is a collection of Airports and is set in code behind, and has a property called Category that I need the combobox to update.

<ListView.View>
            <GridView>
                <GridViewColumn DisplayMemberBinding="{Binding Path=Name}" Header="Airport" Width="100" />
                <GridViewColumn Header="Category" Width="100"  CellTemplate="{StaticResource Category}" />
            </GridView>
        </ListView.View>
+1  A: 

Why have you set SelectedValuePath in your ComboBox? It's difficult to say without seeing your data structures, but that doesn't look right to me.

HTH, Kent

Kent Boogaart
Thanks for looking at this and I have appended the data structure below.
Nailed it! Took out the SelectedValuePath and it worked. THANKS!
A: 

Here is the data that supports the ComboBox and ListView.

Imports System.Collections.ObjectModel

Class Window1

Public Airports As New ObservableCollection(Of Airport)
Public Sub New()
    ' This call is required by the Windows Form Designer.
    InitializeComponent()

    '*************************
    'Dummy data for testing


    Dim anAirports As New Airport
    anAirports.Name = "ABC"
    anAirports.Category = "AA"

    Airports.Add(anAirports)

    anAirports = New Airport
    anAirports.Name = "DEF"
    anAirports.Category = "BB"

    Airports.Add(anAirports)
    '*************************
    'Bind the airports to the list for display
    lstCategories.ItemsSource = Airports

End Sub

End Class

Public Class Airport

''' <summary>
''' Name of the Airport
''' </summary>
''' <remarks></remarks>
Private mName As String
Public Property Name() As String
    Get
        Return mName
    End Get
    Set(ByVal value As String)
        mName = value
    End Set
End Property

''' <summary>
''' Describes the type airport and is selected from a combobox
''' </summary>
''' <remarks></remarks>
Private mCategory As String
Public Property Category() As String
    Get
        Return mCategory
    End Get
    Set(ByVal value As String)
        mCategory = value
    End Set
End Property

End Class

''' ''' Items that are to be displayed in the ComboBox ''' ''' Public Class Categories

Inherits ObservableCollection(Of String)

Public Sub New()
    Me.Add("AA")
    Me.Add("BB")

End Sub

End Class