Solved

Windows Form onchange()

Posted on 2013-11-12
6
239 Views
Last Modified: 2013-11-12
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
Comment
Question by:Isaac
  • 2
  • 2
  • 2
6 Comments
 
LVL 10

Expert Comment

by:joriszwaenepoel
ID: 39642337
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
 
LVL 5

Author Comment

by:Isaac
ID: 39642397
i did that but the label that is to be affected dissappeared.
0
 
LVL 10

Expert Comment

by:joriszwaenepoel
ID: 39642408
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
Don't lose your head updating email signatures!

Do your end users still have the wrong email signature? Do email signature updates bore you or fill you with a sense of dread? You can make this a whole lot easier on yourself by trusting an Exclaimer email signature management solution. Over 50 million users do...so should you!

 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 39642409
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
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 39642420
*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
 
LVL 5

Author Closing Comment

by:Isaac
ID: 39642461
That worked.  Thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Storage devices are generally used to save the data or sometime transfer the data from one computer system to another system. However, sometimes user accidentally erased their important data from the Storage devices. Users have to know how data reco…
Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now