I'm attempting to put the selected value of a combo in a textbox. Both are in a datagrid. I've posted these attempts hereand here. I'm using this tutorial as a guide. This tutorial has been uploaded to skydrive to save on posting code here.
I cannot get the PropertyChanged to fire when changing the item in the combo, like the tutorial does.
Class for combo:
Namespace DentalDB Public Class PartBBilling_Combobox Private _PartBLookup_CPTCode As String Public Property PartBLookup_CPTCode As String Get Return _PartBLookup_CPTCode End Get Set(value As String) _PartBLookup_CPTCode = value End Set End Property Private _PartBLookup_ProcedureDescription As String Public Property PartBLookup_ProcedureDescription As String Get Return _PartBLookup_ProcedureDescription End Get Set(value As String) _PartBLookup_ProcedureDescription = value End Set End Property End Class End Namespace
Class for datagrid:
Namespace DentalDB Public Class PartBBilling Inherits PropertyChangedBase Public Sub New() Me.PartBBilling_Date = DateTime.Now End Sub Private _PartBBilling_RW As Integer Public Property PartBBilling_RW As Integer Get Return _PartBBilling_RW End Get Set(value As Integer) _PartBBilling_RW = value End Set End Property
Private _PartBBilling_CPT As String
Public Property PartBBilling_CPT As String
Get
Return _PartBBilling_CPT
End Get
Set(value As String)
If _PartBBilling_CPT <> value Then
_PartBBilling_CPT = value
RaisePropertyChanged("PartBBilling_CPT")
End If
End Set
End Property<etc...>
xaml:
<Window x:Class="DentalDB.PartBBilling_Window" x:Name="Window" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Part B Billing" Height="300" Width="744" ResizeMode="NoResize" WindowStartupLocation="CenterScreen" Background="#FF336B7B"><Grid Width="667"><Grid.RowDefinitions><RowDefinition Height="139*" /><RowDefinition Height="122*" /></Grid.RowDefinitions><DataGrid AutoGenerateColumns="False" Height="237" HorizontalAlignment="Left" Margin="12,12,0,0" Name="dgPartBBilling" VerticalAlignment="Top" Width="655" AlternationCount="2" AlternatingRowBackground="LightBlue" Grid.RowSpan="2"><DataGrid.Columns><snip><DataGridTemplateColumn Header="CPT Code" Width="75"><DataGridTemplateColumn.CellTemplate><DataTemplate><ComboBox ItemsSource="{Binding PartBCombo, RelativeSource={RelativeSource AncestorType=Window}}" DisplayMemberPath="PartBLookup_CPTCode" SelectedValuePath="PartBLookup_ProcedureDescription" SelectedValue="{Binding PartBLookup_ProcedureDescription, UpdateSourceTrigger=PropertyChanged}" /></DataTemplate></DataGridTemplateColumn.CellTemplate></DataGridTemplateColumn><DataGridTextColumn Header="Procedure Name" Width="150" Binding="{Binding PartBLookup_ProcedureDescription}"/><snip></DataGrid.Columns></DataGrid></Grid></Window>
Setting ItemsSource for datagrid and combo:
Namespace DentalDB Partial Public Class PartBBilling_Window Inherits Window Implements INotifyPropertyChanged Private Sub RaisePropertyChanged(prop As String) RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(prop)) End Sub Private objDS As DataAccess Public Sub New() ' This call is required by the designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call. PartBCombo = New List(Of PartBBilling_Combobox)() From { _ New PartBBilling_Combobox() With { _ .PartBLookup_CPTCode = "D0001", .PartBLookup_ProcedureDescription = "test" _ }, New PartBBilling_Combobox With { _ .PartBLookup_CPTCode = "D2222", .PartBLookup_ProcedureDescription = "Another test" _ } } objDS = New DataAccess() sSQL = "SELECT " & _"tblBilling_PartB.RW, " & _"tblBilling_PartB.BillingDate, " & _"tblBilling_PartB.CPT, " & _"ISNULL(tlkpProcedures_PartB.ProcedureName, '') AS ProcedureName, " & _"tblBilling_PartB.Tooth, " & _"tblBilling_PartB.Quantity, " & _"ISNULL(tlkpProcedures_PartB.BillingAmount * tblBilling_PartB.Quantity, '') AS Total, " & _"tblBilling_PartB.UniqueID " & _"FROM tblBilling_PartB " & _"LEFT JOIN tlkpProcedures_PartB ON tblBilling_PartB.CPT = tlkpProcedures_PartB.CPT " & _"WHERE RW = " & CInt(RW) & " " & _"ORDER BY tblBilling_PartB.BillingDate DESC" dgPartBBilling.ItemsSource = objDS.GetPartBBilling(sSQL) End Sub Public Property PartBCombo As List(Of PartBBilling_Combobox) Get Return _PartBCombo End Get Set(value As List(Of PartBBilling_Combobox)) _PartBCombo = value End Set End Property Private _PartBCombo As List(Of PartBBilling_Combobox) Public Event PropertyChanged(sender As Object, e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged End Class
Both the datagrid and the combo get their itemssource. The textbox does not get updated with the selected value of the combo.
Thanks.