I posted an issue with a project here. I've been asked to upload it so that the person helping me can better see the problem. My DBA is hesitant about creating a backup of the SQL database so I'm trying to create the data locally in code. I'm stuck on how to create this data properly.
I'm fairly new to WPF and EF so I may not use the correct terms. I have a good concept of the basics but understanding collections and classes is something that I struggle with daily.
The project allows the selection of a patient and the dental appointments they have or have had. In the image below, if "Mouse, Mickey" is selected, then his dental appointments display.
Using this code, I've successfully added 2 patients and several dental appointments (dates only) but cannot tie them together so that when "Mouse, Mickey" is selected, his dental appointments display.
Public Sub New() ' This call is required by the designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call. Dim itemsPatient As New List(Of tblPatientDemographic) itemsPatient.Add(New tblPatientDemographic() With { _ .RW = 1, _ .PatientName = "Mouse, Mickey" }) itemsPatient.Add(New tblPatientDemographic() With { _ .RW = 2, _ .PatientName = "Duck, Donald" }) Dim items As New List(Of tblPatientDemographic) items.Add(New tblPatientDemographic() With { _ .tblDentistAppointments = New ObservableCollection(Of tblDentistAppointment)() From { _ New tblDentistAppointment() With { _ .RW = 1, .DentistAppointmentDate = New DateTime(2010, 1, 1) _ }, _ New tblDentistAppointment() With { _ .RW = 1, .DentistAppointmentDate = New DateTime(2012, 1, 1) _ }, _ New tblDentistAppointment() With { _ .RW = 1, .DentistAppointmentDate = New DateTime(2013, 1, 1) _ }, _ New tblDentistAppointment() With { _ .RW = 2, .DentistAppointmentDate = New DateTime(2009, 1, 1) _ }, _ New tblDentistAppointment() With { _ .RW = 2, .DentistAppointmentDate = New DateTime(2011, 1, 1) _ }}}) Dim TblPatientDemographicViewSource As System.Windows.Data.CollectionViewSource = CType(Me.FindResource("TblPatientDemographicViewSource"), System.Windows.Data.CollectionViewSource) 'sort view by patient name. 'TblPatientDemographicViewSource.SortDescriptions.Add(New SortDescription("PatientName", ListSortDirection.Ascending)) TblPatientDemographicViewSource.Source = itemsPatient Dim TblPatientDemographictblDentistAppointmentsViewSource As System.Windows.Data.CollectionViewSource = CType(Me.FindResource("TblPatientDemographictblDentistAppointmentsViewSource"), System.Windows.Data.CollectionViewSource) TblPatientDemographictblDentistAppointmentsViewSource.Source = items
Xaml:
<CollectionViewSource x:Key="TblPatientDemographicViewSource" d:DesignSource="{d:DesignInstance {x:Type local:tblPatientDemographic}, CreateList=True}"/><CollectionViewSource x:Key="TblPatientDemographictblDentistAppointmentsViewSource" Source="{Binding tblDentistAppointments, Source={StaticResource TblPatientDemographicViewSource}}"><CollectionViewSource.SortDescriptions><scm:SortDescription PropertyName="DentistAppointmentDate" Direction="Descending" /></CollectionViewSource.SortDescriptions></CollectionViewSource>
<DataGrid x:Name="TblDentistAppointmentsDataGrid" AutoGenerateColumns="False" EnableRowVirtualization="True" ItemsSource="{Binding Source={StaticResource TblPatientDemographictblDentistAppointmentsViewSource}}"
The above code will allow me to select either patient, but won't display their dental appointments.
Thanks.