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

11

我想创建一个 ListBox 控件,允许用户编辑项目,就像 Launchy 中的扩展列表框一样。在 WinForms 中是否可行?我尝试使用 Autoit Window Info 查看该列表框,其显示为 QWidget(可能与 Qt 相关)。

1个回答

17

尝试使用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();
}

如果有多列,则http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.aspx可能也是一个不错的选择。 :-) - Shadow The Spring Wizard
@akshay:我已经编辑了我的答案并添加了一些新信息。那应该正好符合你的要求。 - Cody Gray

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接