0
votes

I am trying to use a combobox as an input for resolving an IP address, but I have an issue. When a user selected their desired IP from the list, and click 'test', it doesn't seem to recognise the input of the combobox. If I replace the combobox with a text box, it works fine - for some reason, it won't accept the combobox input, even thought the result of both that and the textbox are exactly the same, they are both simple strings.

Dim ip As String = combobox1.Text
    _sock = New TcpClient(ip, port)

If I change 'combobox1.Text' to textbox1.Text, and then enter the IP manually into textbox1, it doesn't work! I also tried 'combobox1.Text.ToString', and that didn't work. This is extremely frustrating, so a quick answer would be appreciated, thanks.

2
Is there a reason you're not using the SelectedItem or SelectedText properties?Rowland Shaw
When using the 'selectedItem' property, it returns exactly the same thing. The 'selectedText' property simple returns: 'No connection could be made because the target machine actively refused it'Sam Stenner
Have you looked with the debugger as to the actual value, as I doubt the SelectedText property returns 'No connection could be made because the target machine actively refused it'Rowland Shaw
Well that's what it said. I am new to this, so can you tell me how to use the debugger to find the actual value please?Sam Stenner
The normal thing to do would be to set a breakpoint, and use the watch window...Rowland Shaw

2 Answers

0
votes
'Returns the Text that has been selected:
Dim ip As String = combobox1.SelectedItem

'Returns the Index of the selected Item (ascending from 0):
Dim ip As String = combobox1.SelectedIndex
0
votes

Ok, I figured it out - the values in the data source for the combobox were taken from a text file, where each part of the string was taken from a different line. Therefore, instead of being 192.186.1.75 (for example), it was infact VbCrLf + 192.186.1.75, which is what caused the error. I guess my next question is, does anyone know how to stop that?

Edit - Nevermind, it's fixed now! Thank you all for your help :)