How do I get this ComboBox hosted by the ListView to update my collection?
I have a ComboBox hosted in a ListView and I need changes in the CombBox to update the supporting 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 Listview. The ItemSource for the ListView is a collection of airports and is set in the code behind, and has a Category property that I need to update the combobox.
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding Path=Name}" Header="Airport" Width="100" />
<GridViewColumn Header="Category" Width="100" CellTemplate="{StaticResource Category}" />
</GridView>
</ListView.View>
0
source to share
2 answers
Here is the data that ComboBox and ListView support.
Imports System.Collections.ObjectModel
Window1 class
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 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 to appear in the ComboBox" "" "" Public class categories
Inherits ObservableCollection(Of String)
Public Sub New()
Me.Add("AA")
Me.Add("BB")
End Sub
End class
0
source to share