cjinsocal581
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.D eviceName)
Next line
__________________________ __________ __________ __
Any ideas?
This should be a simple one.
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.D
Next line
__________________________
Any ideas?
This should be a simple one.
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
Do you want to search for H.323 in TAPI.Lines, or the ComboBox?
Bob
ASKER
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")
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(lin e.DeviceNa me)
Else
Me.ComboBox1.Items.Add("NO DEVICE FOUND")
End If
Next line
End Sub
Bob
Private Sub SearchDevice(ByVal device As String)
For Each line In TAPI.Lines
If line = device Then
Me.ComboBox1.Items.Add(lin
Else
Me.ComboBox1.Items.Add("NO
End If
Next line
End Sub
Bob
ASKER
is device when I would declare the string to look for? (e.g. "H.323")
Sorry,
Usage: SearchDevice("H.323")
Bob
Usage: SearchDevice("H.323")
Bob
ASKER
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(lin e.DeviceNa me)
Else
Me.ComboBox1.Items.Add("NO DEVICE FOUND")
End If
Next line
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(lin
Else
Me.ComboBox1.Items.Add("NO
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(lin e.DeviceNa me)
Else
Me.ComboBox1.Items.Add("NO DEVICE FOUND")
End If
Next line
End Sub
Bob
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(lin
Else
Me.ComboBox1.Items.Add("NO
End If
Next line
End Sub
Bob
ASKER
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.
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(lin e.DeviceNa me)
Else
Me.ComboBox1.Items.Add("NO DEVICE FOUND")
End If
Next line
End Sub
For Each line In TAPI.Lines
If line.DeviceName = device Then
Me.ComboBox1.Items.Add(lin
Else
Me.ComboBox1.Items.Add("NO
End If
Next line
End Sub
ASKER
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
What is the big picture here? What are you really trying to do?
Bob
ASKER
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.
That is all.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect. Thanks.
Dim findItem As Integer = ComboBox1.FindString("H.32
If findItem = -1 Then
ComboBox1.Items.Add("NO DEVICE FOUND")
End If
Bob