Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

How To Filter and Sort a Strongly Typed DataTable and End Up with a Strongly Typed Result

$
0
0

Is there a way to filter and sort a strongly typed DataTable and end up with a strongly typed result?  I know how to use a DataView and to "sort and filter directly in a DataTable," but none of that maintains the strong typing as far as I understand.

Thanks,

Steve

P.S.  I've discovered a way to do this as noted in the code below.  It's awfully brute force.  Does anyone have a more elegant and efficient way to do it?

StronglyTypedDataTableRow[] dr = (StronglyTypedDataTableRow[])
     stronglyTypedDataTable.Select(filterString, sortString, DataViewRowState.OriginalRows);
StronglyTypedDataTable dtFilteredAndSorted =
    (StronglyTypedDataTable) stronglyTypedDataTable.Clone();
if (dr.Length != 0)
    foreach (StronglyTypedDataTableRow drEach in dr)
            dtFilteredAndSorted.ImportRow(drEach);




Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>