开发者

Silverlight 4 C# - How to get value of SelectedItem from a listbox?

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());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜