| | |
Problem with ComboBox display
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
Hi all,
For a combobox I was trying to imitate the behaviour of this code example:http://msdn.microsoft.com/en-us/libr...luemember.aspx
So I have this class:
And a form with a combobox on it and this code:
What I want is: the user selects a planet(yeah there are moons too) name and in the display area of the combo I like to display the gravitational acceleration value. So if I select "Venus" from the dropdownlist, GraviAccelCombo.Text is equal to 8.87, but the word "Venus" gets still displayed instead of "8.87". Have a feeling it must be something very obvious, but I have no clue what so ever.
Any help is again greatly appreciated.
For a combobox I was trying to imitate the behaviour of this code example:http://msdn.microsoft.com/en-us/libr...luemember.aspx
So I have this class:
c# Syntax (Toggle Plain Text)
class Planet { private string myName; private double myGravitationalAcceleration; public Planet(string strName, double Acceleration) { this.myName = strName; this.myGravitationalAcceleration = Acceleration; } public string Name { get { return myName; } } public double GravitationalAcceleration { get { return myGravitationalAcceleration; } } }
c# Syntax (Toggle Plain Text)
public partial class InputData : Form { public InputData() { InitializeComponent(); List<Planet> Planets = new List<Planet>(); Planets.Add(new Planet("Earth at equator 0°", 9.78)); Planets.Add(new Planet("Earth at equinox 23.5°", 9.788)); Planets.Add(new Planet("Earth at lattitude 50°", 9.81)); Planets.Add(new Planet("Earth at pole 90°", 9.83)); Planets.Add(new Planet("Moon", 1.63)); Planets.Add(new Planet("Mars", 3.69)); Planets.Add(new Planet("Venus", 8.87)); Planets.Add(new Planet("Titan", 1.352)); GraviAccelCombo.DataSource = Planets; //add names of properties here, seems cool! GraviAccelCombo.DisplayMember = "Name"; GraviAccelCombo.ValueMember = "GravitationalAcceleration"; } //private void GraviAccelCombo_SelectedIndexChanged(object sender, EventArgs e) //{ // GraviAccelCombo.Text = GraviAccelCombo.SelectedValue.ToString(); //} private void GraviAccelCombo_SelectedValueChanged(object sender, EventArgs e) { if (GraviAccelCombo.SelectedIndex != -1) { GraviAccelCombo.Text = GraviAccelCombo.SelectedValue.ToString(); } } }
What I want is: the user selects a planet(yeah there are moons too) name and in the display area of the combo I like to display the gravitational acceleration value. So if I select "Venus" from the dropdownlist, GraviAccelCombo.Text is equal to 8.87, but the word "Venus" gets still displayed instead of "8.87". Have a feeling it must be something very obvious, but I have no clue what so ever.
Any help is again greatly appreciated.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Make love, no war. Cave ab homine unius libri.
Danny
0
#2 16 Days Ago
I don't think it allows you to override the selection like that when it is databound. You could flip/flop the display member though:
C# Syntax (Toggle Plain Text)
private void comboBox1_DropDown(object sender, EventArgs e) { comboBox1.DisplayMember = "Name"; } private void comboBox1_DropDownClosed(object sender, EventArgs e) { comboBox1.DisplayMember = "GravitationalAcceleration"; }
0
#3 16 Days Ago
Did not really solve my "problem" but you gave me hints to continue.
B.T.W. my design sucked
By introducing an extra textbox (as in the MSDN example btw) I got the best of both worlds: a name and a value. This makes it clearer for the user anyway.
Thanks for the effort.
B.T.W. my design sucked
By introducing an extra textbox (as in the MSDN example btw) I got the best of both worlds: a name and a value. This makes it clearer for the user anyway. Thanks for the effort.
Last edited by ddanbe; 16 Days Ago at 3:20 pm.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Make love, no war. Cave ab homine unius libri.
Danny
![]() |
Similar Threads
- BIOS display problem (Windows NT / 2000 / XP)
- Display Problem with LCD monitor, Need Help (PCI and Add-In Cards)
- DataGridView Problem (VB.NET)
- Problem with ComboBox DataGridView Column (VB.NET)
- about combobox (C#)
- Problem Displaying Items (VB.NET)
- Help...filter the repeated item in combobox... (C++)
- notebook display problem (Monitors, Displays and Video Cards)
- Laptop LCD Display Problem (Monitors, Displays and Video Cards)
- Issue related to combobox.... (VB.NET)
Other Threads in the C# Forum
- Previous Thread: lines in a text file
- Next Thread: Exception:remote connection to database is not allowed !!
| Thread Tools | Search this Thread |
.net 3.5 access activedirectory algorithm analyst array asp.net beginner broadcast c# code combobox commerce concurrency connection console contorl control cs4 data database datagrid datagridview datastructure datetime dba degrees development disabled drawing ecommerce editor enum file form formatting formbox forms index javascript keypress label linux list listbox listview login mailmerge marshalbyrefobject math messagebox mono mysql oracle panel parameters password photoshop php platform pointer post programmer programming query read redirect remoting request.getparameter resource richtextbox robot server smoobjects sql sql-server sqlserver stream string stringformatting table tcpclientchannel text textbox uploadatextfile usercontrol validate validation video visual visual-studio visualbasic webdevelopemnt wia windows winforms wordautomation working wpf







