Very different answer after clarification by the comment on my previous Answer by Hanifuk:
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, string imageFileName) {
this.ItemText = itemText;
this.FImageFileName = imageFileName;
}
public override string ToString() {
return ItemText;
}
internal string ImageFileName { get {return FImageFileName;} }
private string ItemText, FImageFileName;
}
Use this class to add information to your list:
MyList.Add(new ListItemHelper("First day of vacation", "2010-06-01-1343.jpg"));
Now you need to setup a handler for selection of the item in your list:
void ShowMyPicture(string source) {
}
MyList.SelectionChanged += (sender, eventArgs) => {
ListBox listBox = (ListBox)sender;
if (listBox.SelectedItem == null)
ShowMyPicture(null);
else {
ListItemHelper helper = (ListItemHelper)listBox.SelectedItem;
ShowMyPicture(helper.ImageFileName);
}
};
That's it.
—SA