Solved

Windows Form onchange()

Posted on 2013-11-12
6
256 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
accidental deletion - ad recycle bin 3 21
MaxPosPhaseCorrection setting 3 21
Remote control Windows CE 7 50
PDF to JPG 13 45
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In this article, I will show you HOW TO: Install VMware Tools for Windows on a VMware Windows virtual machine on a VMware vSphere Hypervisor 6.5 (ESXi 6.5) Host Server, using the VMware Host Client. The virtual machine has Windows Server 2016 instal…
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…
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.

777 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