I'm trying to create ListBox where I will have key-value pair. Those data I got from class which provides them from getters.
Class:
public class myClass
{
private int key;
private string value;
public myClass() { }
public int GetKey()
{
return this.key;
}
public int GetValue()
{
return this.value;
}
}
Program:
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();
}
It's similar to this topic [ Cannot do key-value in listbox in C# ] but I need to use class that returns values from methods.
Is it possible to do somewhat simple or I'd better rework my thought flow (and this solution) completely?
Thank you for advice!