You are here: > ESRI Forums > arcgis desktop discussion forums > Thread Replies

ArcGIS Desktop Discussion Forums

ArcGIS Desktop - ArcObjects 3rd Party IDE (C++, VB, C#, Delphi, etc.) forum

VB6 - Remove duplicates from combobox   Henry Kovacs May 10, 2007
Re: VB6 - Remove duplicates from combobox   Miles Hitchen May 10, 2007
Re: VB6 - Remove duplicates from combobox   Veeresh Ramireddy May 11, 2007
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject VB6 - Remove duplicates from combobox 
Author Henry Kovacs 
Date May 10, 2007 
Message I have a combobox that is being populated with 3 fields from a shapefile. A single item on the list will look like this: Alder Brook - Franklin County - Stream

The list is being populated, however, the duplicates are not being removed. For example, I have 4 records of Alder Brook - Franklin County - Stream that are in the source shapefile. In the combobox, there are 3 Alder Brook - Franklin County - Stream items.

What is wrong with my code shown below?

thanks,

Henry
 
 
  Dim pWorkspaceFactory As IWorkspaceFactory
  Dim pFeatureWorkspace As IFeatureWorkspace
  Dim pFeatureLayer As IFeatureLayer
  Dim pFC As IFeatureClass

  'Create a new ShapefileWorkspaceFactory object and open a shapefile folder
  Set pWorkspaceFactory = New ShapefileWorkspaceFactory

    Set pFC = pFeatureWorkspace.OpenFeatureClass("gnisHydro")

      Set pCursor = pFC.Search(Nothing, False)
      Set pRow = pCursor.NextRow

      strFieldName = "NAME"
        strFieldName2 = "COUNTY"
      strFieldName3 = "TYPE"
                                                                
      FieldIndex = pFC.FindField(strFieldName)
      FieldIndex2 = pFC.FindField(strFieldName2)                                                       
      FieldIndex3 = pFC.FindField(strFieldName3)

      Set m_Collection = New Collection

      Do While Not pRow Is Nothing
      
      
      
           m_Collection.Add pRow.Value(FieldIndex) & " - " & pRow.Value(FieldIndex2) & " County" & " - " & pRow.Value(FieldIndex3)
        
    
        
        Set pRow = pCursor.NextRow
      Loop

  Set m_pTable = pFC

      'Populate the combo box, remove dups
 
      
       For i = 1 To m_Collection.Count
           If i = 1 Then
               Combo1.AddItem (m_Collection.Item(i))
            ElseIf m_Collection.Item(i) <> m_Collection.Item(i - 1) Then
               Combo1.AddItem (m_Collection.Item(i))
           End If
       Next i
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: VB6 - Remove duplicates from combobox 
Author Miles Hitchen 
Date May 10, 2007 
Message Hi Henry,

The problem is with your loop for adding items to the combobox, the logics not quite right!

Instead of changeing this loop, I'd suggest using IDataStatistics and the UniqueValues property, this is quite easy to implement and it does all the work for you, ie, removes the duplicates.

Let me know if you have any problems getting it to work.

Cheers,
Miles.
 
  Miles Hitchen
Software Engineer
Geospatial Team
Ordnance Survey
UK
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: VB6 - Remove duplicates from combobox 
Author Veeresh Ramireddy 
Date May 11, 2007 
Message Please find here an alternate to avoid duplicate items in combobox.

'Populate the combo box, remove dups
For i = 1 To m_Collection.Count
If Not Combo1.Items.Contains(m_Collection.Item(i)) Then

Combo1.AddItem(x.Item(i))

End If

Next i
 
  Veeru