?
Solved

Add item to ComboBox in VB.NET

Posted on 2005-03-29
16
Medium Priority
?
892 Views
Last Modified: 2012-05-05
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.
0
Comment
Question by:cjinsocal581
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 8
16 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13655575
Start with this:
Dim findItem As Integer = ComboBox1.FindString("H.323")

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

Bob
0
 
LVL 6

Author Comment

by:cjinsocal581
ID: 13655612
So if it finds it, how do I populate it in the ComboBox by itself?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13655643
Ok, maybe I am not understanding you.

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

Bob
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Author Comment

by:cjinsocal581
ID: 13655667
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")
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13655698
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
0
 
LVL 6

Author Comment

by:cjinsocal581
ID: 13655740
is device when I would declare the string to look for? (e.g. "H.323")
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13655749
Sorry,
Usage:  SearchDevice("H.323")

Bob
0
 
LVL 6

Author Comment

by:cjinsocal581
ID: 13655792
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
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13655865
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
0
 
LVL 6

Author Comment

by:cjinsocal581
ID: 13655962
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.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13655972
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
0
 
LVL 6

Author Comment

by:cjinsocal581
ID: 13656012
That took away the error, but now the ComboBox loads a bunch of "NO DEVICE FOUND" entries.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13656046
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
0
 
LVL 6

Author Comment

by:cjinsocal581
ID: 13656078
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.
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 13656105
Got it, sorry again for not giving it my undivided attention:

Private Sub SearchDevice(ByVal device As String)

  Dim deviceFound As Boolean

  For Each line In TAPI.Lines

     If line.DeviceName = device Then
        deviceFound = True            
     End If

  Next line

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

End Sub


Bob
0
 
LVL 6

Author Comment

by:cjinsocal581
ID: 13656161
Perfect. Thanks.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month12 days, 17 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question