Editable ListView
Solution 1
You're asking the wrong question :)
A ListView is not the correct control. Use the DataGridView control. It can be configured to look just like a ListView, but it supports in-place editing of cells.
Solution 2
An ObjectListView will do exactly that and much more. It is a wrapper around a normal .NET ListView. It is open source.
Its website has a Getting Started to help you begin, as well as a whole page devoted to cell editing
Solution 3
You could use the listview's DoubleClick event, and when it is called, you would open a new form where the user would enter a new value for the selected item. Then when the user has pressed ok, you would edit the value of the specific item to what the user has entered.
Solution 4
From the sounds of it, you might want to consider using the DataGridView instead.
Related videos on Youtube
THE DOCTOR
I am a Time-Lord from the planet Gallifrey and the last remaining survivor of my race. I have regenerated several times now as follows: Database Developer -> QA Engineer -> Software Engineer -> Network/Systems Engineer -> Director of IT & Network Engineering.
Updated on July 09, 2022Comments
-
THE DOCTOR almost 2 years
I am looking to create an editable ListView in a C# winforms application where a user may double click on a cell in order to change its contents. It would be great if someone could provide my with some guidance and/or an example. I am not looking to use any commercial products.
-
Admin almost 12 yearsYour question might be answered here: [C#: How do you edit items and subitems in a listview?][1] [1]: stackoverflow.com/questions/471859/…
-
TecMan almost 8 yearsI would disagree that we should not look at ListView alternatives like DataGridView, ObjectListView or even commercial solutions like this, which is cheap enough. Implementing the well-known approach with the textbox editor over ListView items/subitmes has many drawbacks you must solve yourself. For instance, you need to provide a good keyboard interface to edit subitems, the textbox should be scrolled together with the ListView, etc. Using a good 3rd-party solution may save hours of coding, and ultimately, you can even earn more.
-
-
Jeff Yates about 15 yearsThat's a matter of opinion. The DataGridView doesn't always fit the use scenario or provide the required look-and-feel. However, it is a possible alternative, depending on the goals of the OP.
-
Simon Gillbee about 15 yearsThis is a WPF article. Is that what is desired, or are we looking at straight WinForms here? The tags indicate WinForms.
-
Grammarian about 15 yearsActually, it's not a custom control really. It's just a helpful wrapper around a plain ListView. But we won't tell anyone that :)
-
code4life about 13 yearsYou can't do grouped views with the DataGridView. Plus a host of other features that only a ListView supports.
-
Christoffer Lette almost 12 yearsWelcome to SO, Nick. This is a good answer but unfortunately the question is tagged
winforms
, notwpf
. -
Vilius Surblys almost 9 yearsIt also might not be a suitable licence for all projects (as it appears to be under GPLv3)
-
C.J. about 7 yearsThe example is incomplete. For those new to WPF, where do you put the new DataGrid?
-
Derek W about 7 years@CJohnson: This question is about WinForms and not WPF. Please check the question tag and context.
-
Gary Huckabone over 2 yearsTook me a minute, but, uh, yeah ... "ListVIEW" ... view -not- edit. Funny thing, though, DataGridVIEW lets one EDIT. Hmmmm.