Home Forums WPF controls Xceed DataGrid for WPF Empty rows when rebinding

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

    Hi, I’ve just updated to 1.3 Express, for use in an existing xbap app written with 1.2 within VS2008 (RTM). Since upgrading, I find that while the initial databind to a DataTable works fine, when I try to rebind, I get a grid with the correct number of rows I would expect, but the data is not displayed.

    Sometimes if I scroll up and down for a while, some of the rows will reappear, but not all by any stretch of the imagination. I’m not doing anything funky, I do the rebind thus:

    PermsDataGrid.ItemsSource = Perms.DefaultView (where Perms is a DataTable)

    which is exactly how the original (successful) bind is done.

    Any clues?

    JB

    Imported from legacy forums. Posted by Jeremy (had 5465 views)

    Xceed Support
    Member
    Post count: 5658

    I have submitted a bug report for this… Someone will take a look into this shortly, and if nescessary, will ask you questions directly in this thread.

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

    Xceed Support
    Member
    Post count: 5658

    Finally, it seems I was the one assigned to check this.

    When you rebind the grid, are you using the Same data source as the one that was originally bound to the grid?

    If not, do you clear the columns before rebinding the grid ?

    If not, if you scroll horizontally, can you see the columns from the re-bound data source ?

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

    User (Old forums)
    Member
    Post count: 23064

    It depends what you mean by the same data source, it is the same view on the same datatable, all that happens is that between bindings the datatable is repopulated with updated data from the server.

    I’m not clearing any columns before rebinding.

    All the columns fit horizontally in the space allowed for the grid, so no horizontal scrolling. The data set is typically reasonable large (700 rows), and scrolling vertically I do eventually see some of the rows, but I can scroll down see a subset of the rows, scroll back up and back down again, and they will be gone, and perhaps another subset be visible. It does seem to be purely a display issue of some sort.

    Imported from legacy forums. Posted by Jeremy (had 639 views)

    Xceed Support
    Member
    Post count: 5658

    Can you provide a sample on how you repopulate the DataTable? I’d like to take a deeper look at what is happening in the DataTable.

    I ask because I want to verify an hypothesis… Which is that the DataColumn from the DataTable gets “reset” and new instances are created.

    This would unfortunatly have an effect such as the one you describe since the Bindings are using a PropertyDescriptor that is based on the DataColumn instance.

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

    User (Old forums)
    Member
    Post count: 23064

    Ok, not sure how enlightening this will be. The code that requeries the database is

    Private Sub FillPerms(Optional ByVal username As String = “”, Optional ByVal resno As Integer = 0, Optional ByVal company As String = “”)
    Dim wa As New WebAuth.WebAuth
    Dim outcome As Boolean

    Dim ds As DataSet = wa.GetAllPermsList(proxy, outcome, username, resno, company)
    If outcome Then
    m_Perms = ds.Tables(0)
    End If

    PermsDataGrid.ItemsSource = Perms.DefaultView

    End Sub

    GetAllPermsList is a call to a webservice defined as

    Public Function GetAllPermsList(ByVal proxy As Guid, ByRef outcome As Boolean, ByVal username As String, ByVal resno As Integer, ByVal company As String) As DataSet
    If IsSecAdmin(proxy) Then
    Dim db As Database = DatabaseFactory.CreateDatabase(“HHWebAuth”)

    Dim dbc As DbCommand = db.GetStoredProcCommand(“dbo.GetFullPermsList”)
    If username <> “” Then
    db.AddInParameter(dbc, “@username”, DbType.AnsiStringFixedLength, username)
    End If
    If resno > 0 Then
    db.AddInParameter(dbc, “@resno”, DbType.Int32, resno)
    End If
    If company <> “” Then
    db.AddInParameter(dbc, “@companyflag”, DbType.AnsiStringFixedLength, company)
    End If
    Dim ds As New DataSet
    Try
    ds = db.ExecuteDataSet(dbc)
    outcome = True
    Return ds
    Catch ex As Exception
    outcome = False
    Return Nothing
    End Try
    Else
    outcome = False
    Return Nothing
    End If
    End Function

    Let me know if you need anything else, the FillPerms method is called on the original bind as well, normally the rebind is called again to apply a filter to the underlying data, though I have tested rebinding with exactly the same arguments passed to FillPerms and I still get the unwanted behaviour.

    Imported from legacy forums. Posted by Jeremy (had 621 views)

    Xceed Support
    Member
    Post count: 5658

    Based on the code sent, then the issue is effectively caused by the fact the DataColumn are recreated.

    As mentionned earlier, the Binding done with the Data is done through an internal type of PropertyDescriptor (ADO.NET), which uses the DataColumn instance as the “key” to get the appropriate data from the DataRow.

    When the grid is bound initially to the Perms data source, the columns are created and a DisplayMemberBinding is created using the PropertyDescriptor in question.

    When changing the Data Source, new DataColumns are created and the data source is re-evaluated ( so that new columns can be created, if new “columns” are present ). We use the FieldName as the key for the Columns, therefore, we detect the same Columns as before and do not create any new columns. However, the PropertyDescriptor that was used for the DisplayMemberBinding cannot work anymore ( not based on the appropriate DataColumn).

    From there, you have 2 solutions:

    – Before assiging the new data source, you can clear the columns ( myDataGridControl.Columns.Clear(); )

    OR

    – If you have some properties set on the Columns, specify their DisplayMemberBinding manually ( DisplayMemberBinding=”{Binding Path=’myColumnName’, Mode=TwoWay}” )

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

    User (Old forums)
    Member
    Post count: 23064

    Hi Marcus,

    Thanks for this, the second solution was appropriate for me and has done the trick!

    Thanks again,

    JB

    Imported from legacy forums. Posted by Jeremy (had 5337 views)

    User (Old forums)
    Member
    Post count: 23064

    I used this solution to fix my immediate problem.

    However, I would respectfully like to ask that this be classified as a bug.

    I am building my Columns in code-behind, from data. So my solution involves clearing and rebuilding the exact same Columns before each change of the ItemsSource.

    This seems like a huge waste of resources.

    Isn’t there some way this behaviour can be changed internal to the DataGrid? Please…

    Imported from legacy forums. Posted by Mike (had 487 views)

    Xceed Support
    Member
    Post count: 5658

    Ask this nicely, how can one refuse?? [:P]

    This problem has already been addressed and the fix will be available in our upcoming release!!

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

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