I have a string variable that I'm trying to grab the text of the SelectedItem from a listbox when I click on the item.
I'd think that:
String txt = ListBox1.SelectedItem.ToString();
would work, but it only converts the type of the item to a string. For instance, if the item 开发者_如何转开发that I clicked on says "howdy" I want the string to have "howdy" in it.
I'm sure it's an incredibly simple solution, but I'm rather stumped!
Thanks in advance!
-Sootah
Try SelectedValue
String txt = ListBox1.SelectedValue.ToString();
Got it. Here's what I did:
ListBoxItem selected = listBox1.SelectedItem as ListBoxItem;
MessageBox.Show(selected.Content.ToString());
精彩评论