ComboBox SelectedValue is null
- From: T <sw.tejasvi.sn@xxxxxxxxx>
- Date: 20 May 2007 10:02:42 -0700
m_list.SelectedValue returns null in MainForm.valueChanged regardless
of which value is selected. Is this expected behaviour? I was hoping
to get the selected value since the ValueMember property has been set
correctly. Interestingly m_list.SelectedItem *does* return the correct
object.
[code]
using System;
using System.Windows.Forms;
class Attr { // a simple name value class
string m_name;
string m_value;
public Attr(string name, string value){ m_name = name; m_value =
value; }
public string Name { get { return m_name; } }
public string Value { get { return m_value; } }
}
public class MainForm : Form {
public static void Main(string[] args){
Application.Run(new MainForm());
}
ComboBox m_list;
public MainForm(){
m_list = new ComboBox();
Controls.Add(m_list);
m_list.DisplayMember = "Name";
m_list.ValueMember = "Value";
m_list.Items.Add(new Attr("one", "1"));
m_list.Items.Add(new Attr("two", "2"));
m_list.Items.Add(new Attr("three", "3"));
m_list.SelectedValueChanged += new EventHandler(valueChanged);
}
public void valueChanged(object sender, EventArgs args){
if(m_list.SelectedIndex != -1)
Text = m_list.SelectedValue.ToString();
}
}
[/code]
.
- Prev by Date: ComboBox SelectedValue is null
- Next by Date: ComboBox SelectedValue is null
- Previous by thread: ComboBox SelectedValue is null
- Next by thread: ComboBox SelectedValue is null
- Index(es):
Relevant Pages
|