.NET add to combo box if value not already there

kkbenj
kkbenj used Ask the Experts™
on
I am currently filling a combo box from a text file.  But what I really want is just the distinct values, make the insert only if it isn't already in the list.

Here's the code to fill the box on load of my Win form:
-------------------------------------------------------------------------------------------------------------------
Private Sub AxiomLogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim fnCnt As Long        
        Dim fsReq As String
        Dim fsFile As String
        Dim fsLine As String
        Dim fsLoginNm As String
        Dim strTextToFind As String
        Dim intForReading As Long
        Dim objFSO As Object
        Dim objFile As Object

        intForReading = 1
        fnCnt = 0
        fsReq = "Inst Time"
 
        fsFile = "C:\test.txt"
        objFSO = CreateObject("Scripting.FileSystemObject")
        objFile = objFSO.OpenTextFile(fsFile, intForReading, False)

        While Not objFile.AtEndOfStream
            fsLine = objFile.ReadLine
            If InStr(fsLine, fsReq) > 0 Then
                fnCnt = fnCnt + 1
                cbLogins.Items.Add(fsLoginNm)
            End If
        End While

        objFile.Close()
        objFile = Nothing

    End Sub
-------------------------------------------------------------------------------------------------------------------
How can I get this done?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
insert where in Combobox?

and why you are using Scripting.FileSystemObject to open a file when you have File or Fileinfo object

Author

Commented:
swapneel:

The combo box gets loaded with:
 cbLogins.Items.Add(fsLoginNm)

I am using someone else's file reading script.  What do you suggest with File or Fileinfo object?
to add distinct values -
If  cbLogins.Items.Contains(fsLoginNm) Then
         'Item Exists Do Nothing
      Else
         cbLogins.Items.Add(fsLoginNm)
      End If

Author

Commented:
That is PERFECT!  Thanks for your quick responses!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial