Results 1 to 2 of 2

Thread: Some of the textboxes to populate comboboxes on another Form

  1. #1

    Thread Starter
    Registered User
    Join Date
    Mar 2013
    Posts
    9

    Some of the textboxes to populate comboboxes on another Form

    I am trying to get some of the textboxes on one of my forms to populate some comboboxes on another form. I can get the items to populate the combobox but I want them to show as a list of items but they are just in a line with no spacing or anything.

    This is what I have tried

    Private Sub UpdateCrews_Click(sender As Object, e As EventArgs) Handles UpdateCrews.Click

    Form1.ComboBox1.Items.Add(TextBox1c.Text & TextBox8c.Text & TextBox12c.Text)

    End Sub

    There are 18 textboxes for this in total

    How do I get my items to show in a list that the user can select from in the combobox? I know I can do it like:

    Form1.ComboBox1.Items.Add(Textbox1c.Text)
    Form1.ComboBox1.Items.Add(Textbox8c.Text)
    etc
    etc

    but I was wondering if there was a better way to do it.

    NB: There are other textboxes on the form that have nothing to do with the combobox, and wont be used to populate them.

    Any help or guidance would be great
    Diane

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

    Re: Some of the textboxes to populate comboboxes on another Form

    vb.net Code:
    1. Form1.ComboBox1.Items.AddRange({TextBox1c.Text, TextBox8c.Text, TextBox12c.Text})
    You could have found AddRange in the documentation and it would even have shown up in Intellisense when you were typing 'Add'.

    If you don't want to have to specify each TextBox individually then you need to specify a condition that they all satisfy, e.g.
    vb.net Code:
    1. Form1.ComboBox1.Items.AddRange(Me.Controls.
    2.                                   OfType(Of TextBox)().
    3.                                   Where(Function(tb) tb.Name.EndsWith("c").
    4.                                   ToArray())

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