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).
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.
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.
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.
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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With