如何允许用户编辑ListBox中的项目?

vol*_*man 11 .net c# listbox winforms

我想创建一个ListBox允许用户编辑项目的控件,比如Launchy中的扩展名列表框.这在WinForms中可行吗?我尝试在该列表框中使用自动窗口信息,它显示为QWidget(可能与Qt相关).

Cod*_*ray 16

请尝试使用ListView控件.

将其LabelEdit属性设置为True,以允许用户编辑项目的名称.


要允许用户编辑新插入项目上的文本,可以使用以下代码:

private void AddItemToListView()
{
   // Add a new item to the ListView, with an empty label
   // (you can set any default properties that you want to here)
   ListViewItem item = listView1.Items.Add(String.Empty);

   // Place the newly-added item into edit mode immediately
   item.BeginEdit();
}
Run Code Online (Sandbox Code Playgroud)