Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Question about sorting Detail table

$
0
0

Someone posted almost the exact same question here.  I attempted to use that answer in my situation but am not sure how to form the syntax.  I'm using WPF and EF.

I, too, have a master/detail situation that uses a combo box that fills a datagrid.  The combo is sorted by patient name.  I'd like the grid to sort by appointment date.

The EF wizard created the following code (I added the sort description).

        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))

        'Load data by setting the CollectionViewSource.Source property:
        'TblPatientDemographicViewSource.Source = [generic data source]
        _context.tblPatientDemographics.Load()
        TblPatientDemographicViewSource.Source = _context.tblPatientDemographics.Local

The suggested answer (converted to vb.net from c#):

        DirectCast(TblDentistAppointmentsDataGrid.Items, ItemCollection).SortDescriptions.Add(New System.ComponentModel.SortDescription("DentistAppointmentDate", System.ComponentModel.ListSortDirection.Ascending))

I'm not sure where to place this suggested code in my code block.  More importantly, I'm not sure the syntax is correct.  Looking at the xaml, I noticed the resource name:

<DataGrid x:Name="TblDentistAppointmentsDataGrid" AutoGenerateColumns="False" EnableRowVirtualization="True" 
                  ItemsSource="{Binding Source={StaticResource TblPatientDemographictblDentistAppointmentsViewSource}}" 
I thought maybe that resource is what I should apply the sort description to but that is not an option when forming the syntax. 

Thanks.



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>