简体   繁体   中英

Can't turn combobox value into a string - Visual Basic

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.

'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

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 :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM