简体   繁体   English

Silverlight 4 C# - 如何从列表框中获取SelectedItem的值?

[英]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

尝试SelectedValue

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.

相关问题 在Silverlight列表框(C#)中获取SelectedItem的字符串文本 - Getting the String Text of SelectedItem in Silverlight Listbox (C#) LongListSelector C#-如何从分组的数据列表中以字符串形式获取SelectedItem-Windows Phone Silverlight 8.1 - LongListSelector C# - How to get SelectedItem as string from grouped data list - Windows Phone Silverlight 8.1 C#列表框selectedItem不起作用 - c# listbox selectedItem not working 如何通过valuemember c#从列表框中获取DisplayMemeber值? - how to get DisplayMemeber value from listbox by valuemember c#? 从ListBox C#获取值 - Get the value from ListBox C# C# - 如何从特定值设置ComboBox selectedItem? - C# - How to set a ComboBox selectedItem from specific value? C#WPF从ListBox.selectedItem接收到的对象能够修改itemSource集合,怎么办? - C# WPF Received object from ListBox.selectedItem is able to modify itemSource collection, how? 如何在列表框 selecteditem 上显示数组元素? 时间:2019-06-01 标签:c#winforms - How to show array elements on listbox selecteditem ? c# winforms 如何在C#ListBox中获取特定值 - How to get a specific value in C# ListBox 如何从组合框上的selecteditem获得价值驱动并仅针对所选项目与listbox交互 - How to get value Drive from selecteditem on combobox and interact with listbox just for the selected item
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM