将ListBoxView的选定值设置为字符串(C#)
当在ListBoxView中选择一个值时,如何将选择存储为字符串/变量,这样我就可以调用另一个将使用此字符串执行操作的方法?如果ListBoxView中的项目都是字符串,您可以使用将ListBoxView的选定值设置为字符串(C#),c#,.net,windows,string,C#,.net,Windows,String,当在ListBoxView中选择一个值时,如何将选择存储为字符串/变量,这样我就可以调用另一个将使用此字符串执行操作的方法?如果ListBoxView中的项目都是字符串,您可以使用 System.Windows.Forms.ListBox lb= new ListBox(); lb.SelectedItem.ToString(); 否则,我们需要知道您添加到列表框中的项目的类型。如果您使用列表框获取所选项目,如下所示: string item = listBox1.Se
System.Windows.Forms.ListBox lb= new ListBox();
lb.SelectedItem.ToString();
否则,我们需要知道您添加到列表框中的项目的类型。如果您使用列表框获取所选项目,如下所示:
string item = listBox1.SelectedItem.ToString();
如果使用ListView根据MultiSelect属性获取选定项:
string itemName = listView.SelectedItems[0].Name;
foreach (ListViewItem item in ltvMainMenu.SelectedItems)
{
string itemName = item.Name;
}
没有listboxview控件。你在用什么listview或listbox?@Reniuz对不起,这是listview