编辑:几年后重新审视这个问题;以下是根据您使用的 UI 框架执行此操作的方法。这假设您想要更改所选文本。
ASP.Net Web 表单
protected void ChangeListBoxSelectedItemText(string textToChangeTo)
{
lstBoxExample.SelectedItem.Text = textToChangeTo;
}
Run Code Online (Sandbox Code Playgroud)
WPF - 假设 ListBox 包含 Label 对象
// To achieve this in WPF you have to cast the object
// This is because a ListBox can contain numerous types of UI objects
var selectedLabel = (Label)lstBoxExample.SelectedItem;
selectedLabel.Content = "Text to change to";
Run Code Online (Sandbox Code Playgroud)
窗体
// There may very well be a better way to do this
lstBoxExample.Items[lstBoxExample.SelectedIndex] = "New Item";
Run Code Online (Sandbox Code Playgroud)