Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I allow the user to edit items in a ListBox?

I want to create a ListBox control that allows the user to edit items, like the list box for extensions in Launchy. Is this possible in WinForms? I tried using Autoit Window Info on that list box and it shows as QWidget (maybe Qt related).

like image 209
voldyman Avatar asked Mar 06 '11 08:03

voldyman


People also ask

How do I make a ListBox editable?

To edit an item in a listbox, all you need is a simple editbox that overlays on a listbox item. The idea is to create a TextBox control and keep it hidden and show it whenever required. Two events are added to the EditBox. KeyPress event to check if the enter key is pressed when the user has finished editing the item.

What method can we use to add the items into the ListBox?

To insert an item into the list box at a specific position, use the Insert method. To add a set of items to the list box in a single operation, use the AddRange method.

What represents the items in the ListBox control?

In Windows Forms, ListBox control is used to show multiple elements in a list, from which a user can select one or more elements and the elements are generally displayed in multiple columns. The ListBox class is used to represent the windows list box and also provide different types of properties, methods, and events.


1 Answers

Try using a ListView control, instead.

Set its LabelEdit property to True in order to allow the user to edit the names of the items.


To allow the user to edit the text on a newly-inserted item, you can use the following code:

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();
}
like image 165
Cody Gray Avatar answered Oct 02 '22 00:10

Cody Gray