ElrondCT
asked on
Sort array of strongly typed DataRows
I'm sure I'm missing something obvious, but I can't figure out how to sort an array of DataRows that have been drawn from a DataTable. I'm getting the child rows for a particular parent record using
dim drChildA() as dsSet.ChildARow = drParent.GetChildARows
I want to sort these rows, because I can't be certain they were entered in the proper order. (The primary key is a simple counter that's autoincremented for every new record, so it's not useful for this purpose.)
It seems to me there ought to be a way to choose a particular field (or fields) of the DataRow to use to sort, but I can't figure out how to put that into the structure of the Array.Sort method short of defining my own IComparer; I can do that, but it seems like it ought to be reinventing the wheel.
dim drChildA() as dsSet.ChildARow = drParent.GetChildARows
I want to sort these rows, because I can't be certain they were entered in the proper order. (The primary key is a simple counter that's autoincremented for every new record, so it's not useful for this purpose.)
It seems to me there ought to be a way to choose a particular field (or fields) of the DataRow to use to sort, but I can't figure out how to put that into the structure of the Array.Sort method short of defining my own IComparer; I can do that, but it seems like it ought to be reinventing the wheel.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you add these rows to a datatable, you can use the sort method.
ASKER
CodeCruiser: The rows are already in a datatable, so moving them to a new datatable would mean a physical copy which I think would slow things down considerably.
Graye: Thanks for this suggestion. I discovered that I had an IComparer interface written elsewhere in my (large) project to allow doing a sort on the array, so I think I'm going to use that for the moment, though when I have a chance, I'll try to test the two alternatives for performance.
Graye: Thanks for this suggestion. I discovered that I had an IComparer interface written elsewhere in my (large) project to allow doing a sort on the array, so I think I'm going to use that for the moment, though when I have a chance, I'll try to test the two alternatives for performance.