C# 如何将字符串值指定给listbox selectd值

C# 如何将字符串值指定给listbox selectd值,c#,listbox,C#,Listbox,当我给一个字符串时,我想选择listbox项。该字符串名称位于listbox项的上。如何将字符串分配给列表框所选项目。我想您正在寻找类似以下内容: foreach (var item in ListBox.Items) { if (item.Text.Contains(stringToBeSearched)) { //select item in the ListBox ListBox.SelectedValue = item.Value;

当我给一个字符串时,我想选择listbox项。该字符串名称位于listbox项的上。如何将字符串分配给列表框所选项目。

我想您正在寻找类似以下内容:

foreach (var item in ListBox.Items)
{
   if (item.Text.Contains(stringToBeSearched))
   {
       //select item in the ListBox
       ListBox.SelectedValue = item.Value;
       break;
   }
}
希望这有帮助

尝试使用Listbox.Text, 在列表框中搜索与指定文本匹配的项并选择该项

ListBox.Text= "string Value" ; 

感谢你的朋友。非常感谢你。foreach(lbxempname.Items中的ListItem项){string neww=Convert.ToString(项);if(Convert.ToString(项)==Givenstring){item.Selected=true;this.imgbtnedit_单击(null,null);}