Solved

Windows Form onchange()

Posted on 2013-11-12
6
235 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This is an article about Leadership and accepting and adapting to new challenges. It focuses mostly on upgrading to Windows 10.
If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

707 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

13 Experts available now in Live!

Get 1:1 Help Now