DataView - RowFilter for unique values

I'm thinking the answer is 'No', but has anyone ever used a DataView's rowfilter property to view unique rows?

Consider a table containing 20 cities and their states ('WI', 'MN', 'IL', etc).  Column names are City and State.
If I want to see the indivual states that are represented in the table is there any way to say:

dtState.RowFilter = "Unique State"

Any thoughts on how this might be possible?
LVL 3
natejacobsAsked:
Who is Participating?
 
rajaloysiousCommented:
http://support.microsoft.com/default.aspx?scid=kb;en-us;326176
Go to the end to see the code. just use the code

that should do the trick
cheers
0
 
b1xml2Commented:
function string [] GetStates(DataTable table)
{
      ArrayList states = new ArrayList();
      DataRow [] rows = new DataRow [] {table.Rows[0]};
      string [] values;
      string criteria
      while (rows != null && rows.length != 0)
      {
            states.Add((string)rows[0]["State"]);
            values = (string [])states.ToArray(typeof(state));
            criteria = @"State <> '" + string.Join(states,@"' AND State <> '") + @"'";
            rows = table.Select(criteria);
            
      }
      states.Sort();
      return states;
}
0
 
b1xml2Commented:
amendment
=========
criteria = @"State <> '" + string.Join(@"' AND State <> '",values) + @"'";
0
 
natejacobsAuthor Commented:
b1 -

I thought I would have to do something like this.  Thanks for the solution.  
It's simpler than what I had in mind.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.