Link to home
Start Free TrialLog in
Avatar of natejacobs
natejacobs

asked on

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?
Avatar of b1xml2
b1xml2
Flag of Australia image

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;
}
amendment
=========
criteria = @"State <> '" + string.Join(@"' AND State <> '",values) + @"'";
ASKER CERTIFIED SOLUTION
Avatar of rajaloysious
rajaloysious

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of natejacobs
natejacobs

ASKER

b1 -

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