适当长期的灵活性 我将尝试并使用一类物体,然后,你可以做你后来喜欢做的事情,提出事件,改变价值观,而不是使用独特的钥匙,从清单箱中获取真正的物体,而不是仅仅通过形式加以扼制。
public partial class tester : Form
{
public tester()
{
InitializeComponent();
List<MyObject> myObjects = new List<MyObject>();
MyObject testObject = new MyObject("A", "10");
myObjects.Add(testObject);
BindingSource bindingSource = new BindingSource(myObjects,null);
listBox1.DisplayMember = "DisplayValue";
listBox1.DataSource = bindingSource;
}
}
public class MyObject
{
private string _key;
private string _value;
public MyObject(string value, string key)
{
_value = value;
_key = key;
}
public string Key
{
get { return _key; }
}
public string Value
{
get { return _value; }
}
public string DisplayValue
{
get { return string.Format("{0} ({1})", _key, _value); }
}
}