Home Forums WPF controls Xceed DataGrid for WPF DataGrid Binding to LINQ query sort error

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #25128 |

    Hi,

    I am getting the following error when I click on the column to sort:

    The property name ‘Case.time_341’ does not exist.

    The following is the XAML:

    <xcdg:DataGridControl Name=”MeetingsListView” ItemsSource=”{Binding}” Grid.Column=”2″ Margin=”0,5,5,0″ AutoCreateColumns=”False”>
    <xcdg:DataGridControl.Columns>
    <xcdg:Column Title=”Time” FieldName=”Case.time_341″ ReadOnly=”True”/>
    <xcdg:Column Title=”Case” FieldName=”Case.case_no” ReadOnly=”True”/>
    <xcdg:Column Title=”Debtor” FieldName=”Case.case_name” ReadOnly=”True”/>
    <xcdg:Column Title=”Co-Debtor” FieldName=”CoDebtor.name” ReadOnly=”True”/>
    <xcdg:Column Title=”NDR” FieldName=”Case.d_rnd” ReadOnly=”True”/>
    </xcdg:DataGridControl.Columns>
    </xcdg:DataGridControl>

    The Following is the code-behind that binds the DataGrid to a LINQ query:

    var cases =
    from Case in CaselinkData.cases
    where Case.asset == ‘N’
    from Meeting in Case.meetings
    where Meeting.date_341 == date && Meeting.time_341 != “”
    from CoDebtor in Case.cas_names.DefaultIfEmpty()
    orderby Meeting.time_341, Meeting.rank_341
    select new { Case, Meeting, CoDebtor };

    MeetingsListView.ItemsSource = new DataGridCollectionView(cases);

    Imported from legacy forums. Posted by Wally (had 909 views)

    Xceed Support
    Member
    Post count: 5658

    You can workaround this issue by using the DataGridCollectionView.ItemProperties to map to sub-properties instead of going through the Column.FieldName.

    Refer to the “latest” post in this thread for more details:
    http://forums.xceed.com/forums/ShowPost.aspx?PostID=10138

    Imported from legacy forums. Posted by Marcus [Xceed] (had 252 views)

    User (Old forums)
    Member
    Post count: 23064

    That’s great!

    How do I go about adding the sorting to the ItemProperties?

    Thanks

    Imported from legacy forums. Posted by Wally (had 310 views)

    Xceed Support
    Member
    Post count: 5658

    You can refer to the product documentation on sorting:

    <a href=”http://doc.xceedsoft.com/products/XceedWpfDataGrid/Sorting%20Data.html”>http://doc.xceedsoft.com/products/XceedWpfDataGrid/Sorting%20Data.html</a&gt;

    In particular example #1.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 219 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks.

    I got the sorting to work using the ItemProperties. But now when I edit a datetime field, it will save it if I move row to row, but if I try to sort on the datetime column the dates disappear. Am I doing something wrong?

    Here is the xaml:

    <xcdg:DataGridControl Name=”MeetingsListView” ItemsSource=”{Binding}” Grid.Column=”2″ Margin=”0,5,5,0″ AutoCreateColumns=”True”/>

    Here is the code-behind:

    ListBox listBox = sender as ListBox;
    if (listBox == null)
    return;

    DateTime date = (DateTime) listBox.SelectedValue;

    var cases =
    from Case in CaselinkData.cases
    where Case.asset == ‘N’
    from Meeting in Case.meetings
    where Meeting.date_341 == date && Meeting.time_341 != “”
    from CoDebtor in Case.cas_names.DefaultIfEmpty()
    orderby Meeting.time_341, Meeting.rank_341
    select new { Case, Meeting, CoDebtor };

    DataGridCollectionView cv = new DataGridCollectionView(cases);
    cv.ItemProperties.Clear();
    cv.ItemProperties.Add(new DataGridItemProperty(“Time”, “Meeting.time_341”, typeof(string), false));
    cv.ItemProperties.Add(new DataGridItemProperty(“Case”, “Case.case_no”, typeof(string), false));
    cv.ItemProperties.Add(new DataGridItemProperty(“Debtor”, “Case.case_name”, typeof(string), false));
    cv.ItemProperties.Add(new DataGridItemProperty(“Co-Debtor”, “CoDebtor.name”, typeof(string), false));
    cv.ItemProperties.Add(new DataGridItemProperty(“NDR”, “Meeting.d_rnd”, typeof(DateTime?), false));

    LayoutRoot.DataContext = cv;

    Imported from legacy forums. Posted by Wally (had 4400 views)

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.