Out of the box, you can do a lot with the DataView.RowFilter property, but you can’t make use of the top clause. However, if the view contains a column with unique values, you can obtain the same results by setting the Sort property and then generating a RowFilter which uses the in condition.
Here’s a sample:
Note how the delimited string is built. Phil Haack provided an interesting tip on concatenating a delimited string last year. Undoubtedly, we’ve all built delimited strings using our preferred method. If you sift through the post comments, you will see what I mean. Anyhow, I took a liking to the method Joe Cheng uses when he says he’s “feeling lazy and performance is not critical (which is the vast majority of the time).”
That’s a nice solution. I’ve used a PagedDataSource before (http://www.dotnetjunkies.com/W.....33757.aspx), and it works reasonably well if you’re doing simple things with it. Another technique is to add an autoincrement column (http://preview.tinyurl.com/25yolj).
Your solution keeps things simple, which is nice.
[not sure what happened - I left a longer comment yesterday that didn't go through]
Nice indeed. I’ve previously used the PagedDataSource to do this kind of thing, and read about techniques to add an autoincrement column and use “where newcolumn
Hello, here can be found detailed description of Dataview.RowFilter syntax with many examples.
I was actually looking for this on google, and this page was my first result.
Instead of creating a DataView, I decided to go for this:
ds.Tables.Add();
ds.Tables[1].Columns.Add(“Title”);
for (int i = 0; i < itemMax; i++)
{
DataRow row = ds.Tables[1].NewRow();
row["Title"] = ds.Tables[0].Rows[i]["Title"];
ds.Tables[1].Rows.Add(row);
}
That’s disappointing that DVs don’t have TOP…
… oops, had to make a correction.
for (int i = 0; i < MAX(itemMax, ds.Tables[0].Rows.Count); i++)
I ran into something similar before… I kind of like the solution.
Did i say MAX? I meant, Math.Min
ARRGGH
Third time is a charm, eh? Thanks for the contribution, Ralph.
Work is a fucking scam. What kind of world is this that some people spend 60 hours a week pulling fries out of hot grease? What does a $300,000 car say to the cosmos? Please, fucking wipe us out with a giant asteroid already?, is what.