Why is a DataViewManager not sorting?

Posted by Alarion on Stack Overflow See other posts from Stack Overflow or by Alarion
Published on 2008-12-18T20:45:47Z Indexed on 2010/03/08 0:01 UTC
Read the original article Hit count: 190

Filed under:
|
|
|

First off, a quick rundown of what the code is doing. I have two tables: Companies and Clients. There is a one to many relationship between Companies and Clients (one company can have many clients).

In some processing logic, I have both tables loaded into a DataSet - each are DataTables. I have added a DataRelation to set the relationship, and it works when I use GetChildRows on a record from the Companies table.

However, I need to sort the records returned. After googling around some it looks like the DataViewManager is the way to go, and I have examined several basic examples. However, I cannot get my rows sorted. Am I missing something, or am I not using this how it is supposed to be used? Example code:

Dim ldvmManager As New DataViewManager(mdsData)
ldvmManager.DataViewSettings("Companies").Sort = "comName ASC"
ldvmManager.DataViewSettings("Clients").ApplyDefaultSort = False
ldvmManager.DataViewSettings("Clients").Sort = "entLastName ASC, entFirstName ASC"

For Each mdrCurrentCompany in ldvmManager.DataViewSettings("Companies").Table.Rows
    Dim ldrClients() as DataRow = mdrCurrentCompany.GetChildRows("CompaniesClients")
Next

No matter what I do, the first Client returned has a last name that starts with a 'B' and the second has one that starts with a 'A'. From there, the order is all mixed up. If I use my entire data instead of the subset I was using to test with, the first Client returned has a last name that starts with 'J'. It seems like it is still using whatever default sort was being used before I tried to use the DataViewManager.

Any ideas?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about vb.net