CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2001
    Posts
    15

    Listview control - editing cells

    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

  2. #2
    Join Date
    Sep 2002
    Posts
    77
    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.

  3. #3
    Join Date
    Oct 2001
    Posts
    15
    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).

  4. #4
    Join Date
    Dec 2002
    Posts
    6

    Wink

    You can change the subitems values by reinitializing the subitems for the ListViewItem as follows:

    Code:
    // 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);
    Last edited by kevin-k9; May 29th, 2004 at 09:16 PM.
    K9

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured