Filter Dataset with Distinct Values

  • Thread starter Thread starter William Oliveri
  • Start date Start date
W

William Oliveri

Hi all,

I'm have a dataset with contents similar to the following:

Type Name
aaa 300001.pdf
bbb 300001.pdf
ccc 300001.pdf
ddd 300002.pdf
eee 300002.pdf
fff 300003.pdf

I want to display the distinct values of name from this dataset so what I'll
see is:

Name
300001.pdf
300002.pdf
300003.pdf


I need to preserve the structure of the original DS so I can display the
detail. For example, when I have the distinct values the user will click on
one item and in another control, display the associated values.

If the user clicked on:
300001.pdf

In another control it would display:
aaa 300001.pdf
bbb 300001.pdf
ccc 300001.pdf


Thanks for any help.

Bill
 
I see Eric answered it for you, but if you ever need to do the inverse and
show only duplicates, here's a routine I that might help...
Private Sub optDuplicates_CheckedChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles optDuplicates.CheckedChanged
If optDuplicates.Checked Or CType(sender, MenuItem).Text = "Show
Duplicates" Then
Try
If Not optDuplicates.Checked Or AllData.Tbl_Job_Tracking Is
Nothing Then Exit Sub
Dim dr As DataRow
Dim CompareVal As String = String.Empty
Duplicates = New ArrayList
For Each dr In AllData.Tbl_Job_Tracking.Select("",
FieldName)

If CType(dr(FieldName), String) = CompareVal Then
Duplicates.Add(CompareVal)
Debug.WriteLine(CompareVal)
End If
CompareVal = CType(dr(FieldName), String)

Next

Catch ex As InvalidCastException
Debug.Assert(False, ex.ToString)
End Try
ShowOnlyDuplicates(Duplicates)
lblTotalLines.Text = GridSource.Count
End If
End Sub
Public Sub ShowOnlyDuplicates(ByVal Dups As ArrayList)
If Dups.Count = 0 Then
MessageBox.Show("There doesn't appear to be any duplicate
records", "No Duplicates Found", MessageBoxButtons.OK,
MessageBoxIcon.Information)
Exit Sub
End If
Dim sb As New System.Text.StringBuilder
sb.Append(FieldName & " IN( ")

For i As Integer = 0 To Dups.Count - 1
If i = 0 Then
sb.Append("'" & CType(Dups(i), String) & "'")
Else
sb.Append(", '" & CType(Dups(i), String) & "'")
End If
Next
sb.Append(")")
GridSource.RowFilter = sb.ToString
End Sub
 
Back
Top