Search code examples
vb.netvisual-studio-2010listview

Make a cell editable in a ListView


I'm sitting in a VB-project and i have a ListView with 3 cells; a checkbox, a name and another text value. I want the last cell to be editable for the user. The second cell is also okay to have editable, no problems at all.

How can i set cells to be editable?

Right now i'm having this code to fill the ListBox:

Dim row(3) As String
Dim itm As ListViewItem
Dim txtbox As New TextBox

row(0) = ""
row(1) = "some value"
row(2) = "0"


itm = New ListViewItem(row)
itm.SubItems.Add("txtbox")

ListView1.Items.Add(itm

Any tips how to let the user change the last (or both second and last) cell?


Solution

  • The Winforms ListView control cannot be used like a DataGrid.
    Only the first item can be made editable setting the property LabelEdit=True.

    If you really want to be able to edit any 'cells' of the ListView when in Detail mode, you have two possibilities:

    • Switch to a DataGrid
    • Use one of the many extension available for free on the net (An example can be found here)