Sorting Child Rows

  • Thread starter Thread starter mabster
  • Start date Start date
M

mabster

I am trying to retrieve the child rows of a given DataRow using a
relationship, but sort them in the process. There are three ways I can
think of to do this:

1. Use the child table's Select() method to select rows for which the
parent column matches my row's ID, and pass in a sort expression

2. Create a DataRowView from the row (can I do that?), and use the
CreateChildView method

3. Simply use the row's GetChildRows() method and call Array.Sort with a
custom Comparison method

Has anyone done any performance comparisons on these three methods of
returning sorted child rows? Which one am I better off using? I'm
currently enjoying success with the third option, using comparisons like
this:

int CompareRows(DataRow x, DataRow y)
{
return
x["MyStringColumn"].ToString().Compare(y["MyStringColumn"].ToString());
}

Your thoughts?

Cheers,
Matt
 
Hi,

There is a fourth method:
Create a proper DataView and sort it.
I would opt for a simpliest method (this one - evertyhing in a single line).
 
Miha said:
Hi,

There is a fourth method:
Create a proper DataView and sort it.
I would opt for a simpliest method (this one - evertyhing in a single line).
How does the DataView approach go with typed DataSets? I'm using them
throughout my application, and the ease with which I can use the
GetXXXRows() on a strongly-typed DataTable is really great.

My application doesn't display the data in a grid or anything. The
sorting I'm doing is purely for things like populating ComboBoxes or
ListBoxes. Is it worth introducing DataViews into my app for this
limited use?
 
mabster said:
How does the DataView approach go with typed DataSets? I'm using them
throughout my application, and the ease with which I can use the
GetXXXRows() on a strongly-typed DataTable is really great.

My application doesn't display the data in a grid or anything. The sorting
I'm doing is purely for things like populating ComboBoxes or ListBoxes. Is
it worth introducing DataViews into my app for this limited use?

But you are binding them as DataSource?
 
Miha said:
But you are binding them as DataSource?

Nope. No DataBinding in my app at all. All I ever do is iterate through
arrays of DataRow (or DataRow descendants at any rate).
 
Back
Top