DataView - RowFilter for unique values

Posted on 2005-04-15
Last Modified: 2007-11-27
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?
Question by:natejacobs
    LVL 23

    Expert Comment

    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)
                values = (string [])states.ToArray(typeof(state));
                criteria = @"State <> '" + string.Join(states,@"' AND State <> '") + @"'";
                rows = table.Select(criteria);
          return states;
    LVL 23

    Expert Comment

    criteria = @"State <> '" + string.Join(@"' AND State <> '",values) + @"'";
    LVL 8

    Accepted Solution

    Go to the end to see the code. just use the code

    that should do the trick
    LVL 3

    Author Comment

    b1 -

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

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Problem with C# 1 44
    Contant UI messages in .NET 1 23
    Refresh page ASP.NET C# 3 39
    Allow users to select all checkboxes 6 47
    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now