[英]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. 我有一个字符串变量,当我点击该项目时,我正试图从列表框中获取SelectedItem的文本。
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. 例如,如果我点击的项目说“你好”,我希望字符串中有“howdy”。
I'm sure it's an incredibly simple solution, but I'm rather stumped! 我确信这是一个非常简单的解决方案,但我很难过!
Thanks in advance! 提前致谢!
-Sootah -Sootah
String txt = ListBox1.SelectedValue.ToString();
Got it. 得到它了。 Here's what I did: 这是我做的:
ListBoxItem selected = listBox1.SelectedItem as ListBoxItem;
MessageBox.Show(selected.Content.ToString());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.