[RESOLVED] Multi Line String - 1 line = new entry to combobox?
Ok, So I have a string that has its formats like this:
Code:
Line 1
Line 2
Line 3
Line 4
I want each line, as its own entry on a combo box.
I am having a MAJOR brain fart, as I know I know this... but I can't think right now.
Anyone willing to help me out? Thanks in advance.
Re: Multi Line String - 1 line = new entry to combobox?
You could do this:
vb.net Code:
myComboBox.Items.AddRange(myTextBox.Lines)
or this:
vb.net Code:
myComboBox.DataSource = myTextBox.Lines
The effect is similar but not quite the same, so one may be better than the other in certain circumstances.
Re: Multi Line String - 1 line = new entry to combobox?
That would imply I had a textbox control ya?
I'm using an actual string (dim this as string)
this has the Line 1, Line 2, stuff.
However, I do appreciate your input, and i'll give it a go.
Thanks.
Re: Multi Line String - 1 line = new entry to combobox?
I just did the quick work around for it...
Code:
Dim gamenames As String = instance.DownloadString("http://localhost/readgames.php")
Debug.Print(gamenames)
Dim gamenamestxt As New TextBox
gamenamestxt.Text = gamenames
ComboBox1.DataSource = gamenamestxt.Lines
Re: [RESOLVED] Multi Line String - 1 line = new entry to combobox?
Or you could just split via Environment.NewLine and then add THAT range.
Code:
Dim gamenames() As String = instance.DownloadString("http://localhost/readgames.php").Split(Environment.Newline)
ComboBox1.Items.AddRange(gamesnames)
Re: [RESOLVED] Multi Line String - 1 line = new entry to combobox?
Hmmm... I think I saw "multi-line" and just assumed a TextBox for some reason. J-Deezy is on the right track, although it should more correctly be:
Code:
Dim gamenames() As String = instance.DownloadString("http://localhost/readgames.php").Split(New String() {Environment.Newline}, StringSplitOptions.None)
ComboBox1.Items.AddRange(gamesnames)
Re: [RESOLVED] Multi Line String - 1 line = new entry to combobox?
Ahhh, that's how you're supposed to do it. Thanks, I was always why my way worked but when I turned Option Strict on it screwed up.