• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 269
  • Last Modified:

Windows Form onchange()

Hi All,

I am new to windows form development and need a little help.  I created the form you see below:
Form
The "Types:" drop down has the following options 'Quotes', 'Poems' and 'Stories'.  What I would like to have happen is depending on what is chosen, the 'Story' label changes to reflect the selection.  So, if 'Quotes' is selected, 'Story' will change to 'Quotes', etc.

I did modify the code and here's what happens when I make a selection:
Entry Error
Here's my code:
namespace QuotesPoemsStories
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            TypeOfChoice.Text = e.ToString();
        }
    }
}

Open in new window


Any help would be great.

Thanks!
0
Isaac
Asked:
Isaac
  • 2
  • 2
  • 2
1 Solution
 
joriszwaenepoelCommented:
The type of e is EventArgs.  It has nothing to do with the value that is selected in the combobox.  The value you want is combobox1.SelectedText

You should replace

TypeOfChoice.Text = e.ToString();

with

TypeOfChoice.Text = combobox1.SelectedText;
0
 
IsaacSharePoint Client Side DeveloperAuthor Commented:
i did that but the label that is to be affected dissappeared.
0
 
joriszwaenepoelCommented:
I typed that code in the browser, and I didn't test it.  Sorry for that.

It is the SelectedValue property that you need to use, not SelectedText.  

Hope this helps.
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Not quite...you actually want SelectedItem():
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex != -1)
            {
                TypeOfChoice.Text = comboBox1.SelectedItem.ToString();
            }
        }

Open in new window

0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
*SelectedValue() applies if you've set DisplayMember() and ValueMember() for your ComboBox.

If you've only added strings to your ComboBox thru the IDE then use SelectedItem().
0
 
IsaacSharePoint Client Side DeveloperAuthor Commented:
That worked.  Thanks!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now