Articles in this section
Category / Section

How to Display All Unique Values in a Textbox

Published:
Updated:

Many users prefer to display all unique field values in a text box. This requirement can be achieved using the Code Module and LookupSet function. Follow the steps below to show all unique dataset field values in the text box.

  1. To remove duplicate values and return the unique values as a comma-separated string, include the provided VB code module. Embed the code module function into the Code Section of your report. This module introduces a function named RemoveDuplicates, which eliminates duplicate values from an array and generates a comma-separated string of unique values.

    image.png

    Function RemoveDuplicates(items As Object()) As String
        Dim uniqueValues As New System.Collections.Generic.Dictionary(Of String, Boolean)
    
        For Each item As Object In items
            Dim value As String = item.ToString()
            If Not uniqueValues.ContainsKey(value) Then
                uniqueValues.Add(value, True)
            End If
        Next
    
        Return String.Join(", ", uniqueValues.Keys)
    End Function
    
  2. Right-click on the desired text box, then select Expression.

    image.png

  3. Insert the following expression into the text box to retrieve unique values as a comma-separated list:

    image.png

    =Code.RemoveDuplicates(LookupSet(1, 1, Fields!Name.Value, "DataSet1"))
    

Replace DataSet1 with your dataset and Name with the appropriate field name.

  1. Save the changes and preview the report to visualize all unique values within the text box.
    image.png

The above-designed report can be downloaded here.

Was this article useful?
Like
Dislike
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied