Click to See Complete Forum and Search --> : Listview control - editing cells


Tisme
September 13th, 2002, 01:54 AM
I have a listview, I want to be able to edit the cells of various rows on a column by column basis.

Any suggestions, or pointers to sample code that allow this?

(I can do it under VC++, but would prefer to write the app in C#)

Tnaks for any suggestions.

Glenn Dunn

alpha137
September 14th, 2002, 02:10 PM
I believe that in a ListView control you can only edit the label of the ListViewItem (the first column) but not the ListViewSubItems.
This is true for the SysListView32 control which has been heavily used in C++.

If you want to edit the content of every column you should consider to use the DataGrid control. There is no need to bind it to database - you can create a standalone DataTable and fill it with your data.

Tisme
September 15th, 2002, 06:17 PM
It is something that can be done in C++, I have a class that inherits from the CListView control, and overrides messages to create a temporary edit control in row x column y when the user clicks, so it it possible.

I'm fairly sure the base code came from codeguru, so was hoping someone might have developed a similar over-ridden control under c#.

I'll try the datagrid, just would have preferred the customised listview (imho it looks better).

kevin-k9
May 29th, 2004, 09:14 PM
You can change the subitems values by reinitializing the subitems for the ListViewItem as follows:


// Clear the SubItemCollection
myTestListItem.SubItems.Clear();

// Create a string array to hold the new values
string[] newItems = new string[]{
newString1,
newString2,
newString1,
};

// Add the items to the subItemCollection
myTestListItem.SubItems.AddRange( newItems );

// After the SubItems collection is cleared, it is reinitialized with a
// default string.
// Remove the default SubItem for the collection.
myTestListItem.SubItems.RemoveAt(0);

;)