キーと値のペアを持つ ListBox を作成しようとしています。ゲッターからそれらを提供するクラスから取得したこれらのデータ。
クラス:
public class myClass
{
private int key;
private string value;
public myClass() { }
public int GetKey()
{
return this.key;
}
public int GetValue()
{
return this.value;
}
}
プログラム:
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();
}
このトピック [ C# のリストボックスでキー値を実行できません] に似ていますが、メソッドから値を返すクラスを使用する必要があります。
やや単純にすることは可能ですか、それとも思考の流れ (およびこの解決策) を完全に作り直した方がよいでしょうか?
アドバイスありがとうございます!