Solved

Windows Form onchange()

Posted on 2013-11-12
6
264 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 
LVL 86

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 86

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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Learn how to PXE Boot both BIOS & UEFI machines with DHCP Policies and Custom Vendor Classes
This article summaries thoughts and ideas from two years of sustained use. It provides good reasoning to make the jump to Windows 10.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

687 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