lundi 30 novembre 2015

How to read grouped records in XamDataGrid when grouping is set programatically in tests?

I'm trying to write some test scenarios for the XamDataGrid. In these scenarios I'd like to set the grouping on a single Field. This code causes the grid to group as expected when I run the app and double-click the grid:

    Private Sub MyGrid_MouseDoubleClick(sender As Object, e As MouseButtonEventArgs) Handles MyGrid.MouseDoubleClick
        Dim xamDataGrid As XamDataGrid = CType(sender, XamDataGrid)
        Dim field As Field = xamDataGrid.FieldLayouts(0).Fields("A")
        Dim fieldSortDescription As New FieldSortDescription With {.Field = field, .Direction = ListSortDirection.Ascending, .IsGroupBy = True}

        xamDataGrid.FieldLayouts(0).SortedFields.Add(fieldSortDescription)
    End Sub

In tests, after running something very similar the Records and ViewableRecords collections do not reflect the grouping. xamDataGrid.ViewableRecords(0) is a DataRecord and not a GroupByRecord. Here's the code from the test:

    <TestMethod()>
    Public Sub Test()
        Dim xamDataGrid As New XamDataGrid

        xamDataGrid.DataSource = dataSource.DefaultView
        xamDataGrid.BeginInit()
        xamDataGrid.EndInit()

        Dim field As Field = xamDataGrid.FieldLayouts(0).Fields("A")
        Dim fieldSortDescription As New FieldSortDescription With {.Field = field, .Direction = ListSortDirection.Ascending, .IsGroupBy = True}
        xamDataGrid.FieldLayouts(0).SortedFields.Add(fieldSortDescription)

        ' exception thrown here because xamDataGrid.ViewableRecords(0) is a DataRecord
        Dim groupByRecord As GroupByRecord = CType(xamDataGrid.ViewableRecords(0), GroupByRecord)
        ' ...
    End Sub

How can the grid be refreshed or otherwise forced to reflect the grouping set by the code?

Thanks for your time.

Aucun commentaire:

Enregistrer un commentaire