tags:

views:

8178

answers:

3

How do you edit items and subitems in a listview? Let's say I have a listview with 3 columns,and subitems,

Car Brand | Car Name | Car Year
Ford      | Mustang  | 2000
Dodge     | Charger  | 2007

How would I Add items like that to listview and how would I edit let's say the Car Name on which ever row by index[] if I needed to edit at runtime at firing of an event?

+3  A: 

If you're looking for "in-place" editing of a ListView's contents (specifically the subitems of a ListView in details view mode), you'll need to implement this yourself, or use a third-party control.

By default, the best you can achieve with a "standard" ListView is to set it's LabelEdit property to true to allow the user to edit the text of the first column of the ListView (assuming you want to allow a free-format text edit).

Some examples (including full source-code) of customized ListView's that allow "in-place" editing of sub-items are:

C# Editable ListView
In-place editing of ListView subitems

CraigTP
I recommend the In-place editor. Much easier to implement.
John M
A: 

"..ListView is to set it's LabelEdit.." yo can edit only firs column.. but you can't edit all subitems.

fucinas
+1  A: 

Sorry, don't have enough rep, or would have commented on CraigTP's answer.

I found the solution from the 1st link - C# Editable ListView quite easy to use. The general idea is to

  • identify the SubItem that was selected and overlay a TextBox with the SubItem's text over the SubItem
  • give this TextBox focus
  • change SubItem's text to that of TextBox's when TextBox loses focus

What a workaround for a seemingly simple operation :-|

lazo