Link to home
Start Free TrialLog in
Avatar of cjinsocal581
cjinsocal581Flag for United States of America

asked on

Add item to ComboBox in VB.NET

I need to be able to add an itme to a ComboBox in VB.NET when it finds a particular item.

This example uses the TAPI devices available. So lets say I am looking for the H.323 item, how would I search for that one and populate it in the ComboBox if it is there? And of it is NOT there, populate the ComboBox with "NO DEVICE FOUND".

________________________________________________
For Each line In TAPI.Lines
            ComboBox1.Items.Add(line.DeviceName)
Next line
________________________________________________

Any ideas?

This should be a simple one.
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Start with this:
Dim findItem As Integer = ComboBox1.FindString("H.323")

If findItem = -1 Then
  ComboBox1.Items.Add("NO DEVICE FOUND")
End If

Bob
Avatar of cjinsocal581

ASKER

So if it finds it, how do I populate it in the ComboBox by itself?
Ok, maybe I am not understanding you.

Do you want to search for H.323 in TAPI.Lines, or the ComboBox?

Bob
Sorry bout that.

I would want to search the TAPI.Lines for it then populate the ComboBox if it finds it. (Of course, if it doesn't, populate it with the "No Device Found")
Is this better?

Private Sub SearchDevice(ByVal device As String)

  For Each line In TAPI.Lines

     If line = device Then
        Me.ComboBox1.Items.Add(line.DeviceName)
     Else
        Me.ComboBox1.Items.Add("NO DEVICE FOUND")
     End If

  Next line

End Sub

Bob
is device when I would declare the string to look for? (e.g. "H.323")
Sorry,
Usage:  SearchDevice("H.323")

Bob
I am getting an error stating it is not producing a value. Here is what I have so far...

Dim line As TAPI.TAPILine
        TAPI.initialize()
        Dim device As String
        device = SearchDevice("H.323")
        For Each line In TAPI.Lines
            If line = device Then
                Me.ComboBox1.Items.Add(line.DeviceName)
            Else
                Me.ComboBox1.Items.Add("NO DEVICE FOUND")
            End If
 Next line
Private Sub Initialize

        TAPI.initialize()

        SearchDevice("H.323")

End Sub


Private Sub SearchDevice(ByVal device As String)

  For Each line In TAPI.Lines

     If line = device Then
        Me.ComboBox1.Items.Add(line.DeviceName)
     Else
        Me.ComboBox1.Items.Add("NO DEVICE FOUND")
     End If

  Next line

End Sub

Bob
This is the error I get with the above code:

Operator '=' is not defined for types 'TAPI.TAPILine' and 'String'. Use 'Is' operator to compare two reference types.
Private Sub SearchDevice(ByVal device As String)

  For Each line In TAPI.Lines

     If line.DeviceName = device Then
        Me.ComboBox1.Items.Add(line.DeviceName)
     Else
        Me.ComboBox1.Items.Add("NO DEVICE FOUND")
     End If

  Next line

End Sub
That took away the error, but now the ComboBox loads a bunch of "NO DEVICE FOUND" entries.
Ok, enough is enough.  I haven't spent enough time understanding you're explanation and implementation, and we'll just keep going around and around, and I don't really have time to do that.

What is the big picture here?  What are you really trying to do?

Bob
Sorry to have made this inconvenient for you but all I am trying to do is search the items in the lines, and if it finds "H.323" to add it to the combo box by itself and if it does not find it, to add NO DEVICE FOUND.

That is all.
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Perfect. Thanks.