Even though the description of desired behavior is really ambiguous and not clear, you need to know just one idea.
The thing is: don't store string as the element of the list part of combo box. An object of any other type can be an element. The only problem is: what text will be shown in the item when it is presented in UI? The answer is: whatever is returned by the method
ToString
. So, the solution is: override the virtual method
Object.ToString
in your structure or class to be used as the list element.
First, you need to create some class for an item to store in the list. You requirements mean that it serve dual purpose: to show some text in the list and also to provide information for image presentation. Let's assume this is image file name (could be more complex; this is just for example). To show this item in the list, all you need it to override
object.ToString()
:
internal class ListItemHelper {
internal ListItemHelper(string itemText, double data) {
this.ItemText = itemText;
this.fData = data;
}
public override string ToString() {
return ItemText;
}
internal double Data { get {return fData; } }
string ItemText;
double fData;
}
Use this class to add information to your list:
MyList.Add(new ListItemHelper("Payment", 21.52));
Every time you need some data associated, say, with selected item, you need to type cast the selected item to
ListItemHelper
and use data in your calculations.
You should do everything else by yourself. You did not even specify the UI library you use (please see my comment to the question), so further code samples would make no sense. I don't even know exact type of
ComboBox
you are using. Always specify all relevant detail when asking a question.
—SA