|
-
Oct 16th, 2010, 11:28 PM
#1
Thread Starter
Fanatic Member
[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.
-
Oct 16th, 2010, 11:36 PM
#2
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.
-
Oct 16th, 2010, 11:40 PM
#3
Thread Starter
Fanatic Member
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.
-
Oct 16th, 2010, 11:43 PM
#4
Thread Starter
Fanatic Member
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
-
Oct 16th, 2010, 11:53 PM
#5
Fanatic Member
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)
If I helped you out, please take the time to rate me 
-
Oct 17th, 2010, 12:37 AM
#6
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)
-
Oct 17th, 2010, 01:03 AM
#7
Fanatic Member
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.
If I helped you out, please take the time to rate me 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|