Results 1 to 4 of 4

Thread: how do i select items from combox?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2007
    Posts
    208

    Arrow how do i select items from combox?

    i am using VS 2008.

    and i am developing windows form application, i am a beginner for this.

    i have a comboBox that contains colors, these are, Blue,Red,Green,Yellow and Pink.

    I have populated them from the graphical interface in my visual studio project.

    now i want to select one color so that i can assign it to my text box.

    my comboBox name is comboBox1.

    my textbox is TextBox1


    if (combox1.selectedItem=="color")

    then

    textbox1.text="selected Color name"


    so how can i assign it to my textbox1 by selecting from the dropdown list in my combobox1.

    thanks for your hellping
    Last edited by nebrom; Feb 8th, 2011 at 06:26 AM.

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

    Re: how do i select items from combox?

    In this case, you simply get the Text of the ComboBox and assign it to the Text of the TextBox. For those controls that it's logical, the Text property is where you get or set the text displayed in the control.
    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
    Addicted Member
    Join Date
    Mar 2007
    Posts
    208

    Re: how do i select items from combox?

    thanks for you reply, but sorry i did not get you.

    what i want is if i select Blue, then i will display it in textbox the name color Blue.

    if i select green, then the value of the texbox1 one will be Green so can u code it.

    so can u put somecodes thanks

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

    Re: how do i select items from combox?

    Rather than waiting for someone to write your code for you, read and think. You obviously already know how to set the Text property of a TextBox, because you've posted code that does it. It's not a stretch to get the Text property of a ComboBox, is it?

    As for when to do it, handle the SelectedIndexChanged event of the ComboBox, which is raised each time the user changes the selection. If you can handle the Click event of a Button then you can handle the SelectedIndexChanged event of a ComboBox.
    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

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