我想重命名列表框中的选定项目。
我该怎么做?
谢谢。
最佳答案
编辑:几年后重新审视;以下是根据所使用的UI框架执行此操作的方法。这假设您要更改所选文本。
ASP.Net Web窗体
protected void ChangeListBoxSelectedItemText(string textToChangeTo)
{
lstBoxExample.SelectedItem.Text = textToChangeTo;
}
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";
WinForms
// There may very well be a better way to do this
lstBoxExample.Items[lstBoxExample.SelectedIndex] = "New Item";