Results 1 to 7 of 7

Thread: [RESOLVED] Multi Line String - 1 line = new entry to combobox?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2007
    Posts
    520

    Resolved [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.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Multi Line String - 1 line = new entry to combobox?

    You could do this:
    vb.net Code:
    1. myComboBox.Items.AddRange(myTextBox.Lines)
    or this:
    vb.net Code:
    1. myComboBox.DataSource = myTextBox.Lines
    The effect is similar but not quite the same, so one may be better than the other in certain circumstances.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2007
    Posts
    520

    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.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2007
    Posts
    520

    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

  5. #5
    Fanatic Member
    Join Date
    Aug 2010
    Posts
    624

    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

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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)
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7
    Fanatic Member
    Join Date
    Aug 2010
    Posts
    624

    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
  •  



Click Here to Expand Forum to Full Width