我正在尝试创建 ListBox,其中我将拥有键值对。我从课堂上获得的那些数据是从 getter 那里获得的。
班级:
public class myClass
{
private int key;
private string value;
public myClass() { }
public int GetKey()
{
return this.key;
}
public int GetValue()
{
return this.value;
}
}
Run Code Online (Sandbox Code Playgroud)
程序:
private List<myClass> myList;
public void Something()
{
myList = new myList<myClass>();
// code for fill myList
this.myListBox.DataSource = myList;
this.myListBox.DisplayMember = ??; // wanted something like myList.Items.GetValue()
this.myListBox.ValueMember = ??; // wanted something like myList.Items.GetKey()
this.myListBox.DataBind();
}
Run Code Online (Sandbox Code Playgroud)
它类似于本主题 [ Cannot do key-value in listbox in …