[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Add item to ComboBox in VB.NET

Posted on 2005-03-29
16
Medium Priority
?
974 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
  • 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
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…

612 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