How can I hide duplicate field values in my GridView?

Hi all,

I have a GridView, which displays a result set, but many of the field values are duplciates (ie. it is selecting a list of all relationships for person "X", so person "X"'s name, city, address, etc. shows up in every single result). Is there a way that I can tell the GridView to "hide duplicates" in much the same way you can do this for reports in SS Reporting Services?

All help is greatly appreicated!
OddiCAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

OddiCAuthor Commented:
EDIT: I shuold say: so person "X"'s name, city, address, etc. shows up in every single RECORD of the result set displayed in the GridView- I want to hide these duplicate values to make the gridview more readable)
0
VBRocksCommented:
Is Each row a complete duplicate, or is there at least 1 column in each row that has data that is not
duplicate?

0
OddiCAuthor Commented:
There are several other columns that are not duplicates.... I think I should just specify DISTINCT for the fields I do not want to display as dupllicates and make sure the JOINs are OUTER JOINs... this way I will have NULLs for the fields I am trying to hide duplicates for (and I can sort, etc. on the other fields).

Does this sound like a 'sound' approach? ((I was just hoping that maybe GridView had a property like Column.DisplayDuplicates or something that i could set in the app vs. changing the SP in the database...
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

VBRocksCommented:
Well, is it possible to just hide those columns, or is there some data in those columns that you need to
see?

0
OddiCAuthor Commented:
I want to display the first (DISTINCT) value, and hide this value (as it is duplicate) in all of the other records that have that duplicate value.

I *think* what I plan on doing will work...
0
VBRocksCommented:
That could work, however, if you allow the user to perform sorting on any field, then that will mess it up.

Additionally, I don't think DISTINCT is going to work for you the way you are expecting.  DISTINCT works
when every column for each row is exactly the same.  I don't think you can use DISTINCT on some
columns and not on others.

What you'll probably have to do, is loop through each row in the table, checking the vaue of the column that you don't want duplicates in, removing the values if they are duplicates.  Do all this before you
set the table as the DataGrid's DataSource.

Here's an example:

        'Create a table for this example:
        Dim table As New DataTable()
        table.Columns.Add("ID")
        table.Columns.Add("ITEM")

        'Add 5 rows, the first 3 rows have duplicated "ITEM"
        table.Rows.Add(1, "Item 1")
        table.Rows.Add(2, "Item 1")
        table.Rows.Add(3, "Item 1")
        table.Rows.Add(4, "Item 2")
        table.Rows.Add(5, "Item 3")

        'Get only the distinct rows:
        '    This will return ALL rows, because there are no duplicates.
        '    Every row is unique, because the value of column ID is unique
        'Dim distinctTable As DataTable = _
        'table.DefaultView.ToTable(True, New String() {"ID", "ITEM"})

        'Me.DataGridView1.DataSource = distinctTable

        'Stores value of previous ITEM
        Dim prevValue As String = String.Empty

        'Example:  Loop through each column and "hide" it
        '     if it is a duplicate of the previous row
        For Each row As DataRow In table.Rows
            If row.Item("ITEM").ToString() <> prevValue Then
                prevValue = row.Item("ITEM")
            Else
                row.Item("ITEM") = String.Empty
            End If
        Next

        Me.DataGridView1.DataSource = table


VBRocks
MS MVP
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
OddiCAuthor Commented:
That sounds like exactly what I need. Thank you friend!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.