?
Solved

DataView - RowFilter for unique values

Posted on 2005-04-15
4
Medium Priority
?
2,071 Views
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?
0
Comment
Question by:natejacobs
  • 2
4 Comments
 
LVL 23

Expert Comment

by:b1xml2
ID: 13792366
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
 
LVL 23

Expert Comment

by:b1xml2
ID: 13792377
amendment
=========
criteria = @"State <> '" + string.Join(@"' AND State <> '",values) + @"'";
0
 
LVL 8

Accepted Solution

by:
rajaloysious earned 2000 total points
ID: 13792517
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
 
LVL 3

Author Comment

by:natejacobs
ID: 13792595
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

864 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