[RESOLVED] Add an Item to a ListView in VitualMode ?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: [RESOLVED] Add an Item to a ListView in VitualMode ?

Threaded View

  1. #1
    Join Date
    Jun 2008
    Posts
    57

    [RESOLVED] Add an Item to a ListView in VitualMode ?

    Hi,
    I'm gonna add an item to a ListView in VirtualMode.
    Below is my C# code to do that :

    Code:
    listView1.VirtualMode = true;
    listView1.VirtualListSize = query.Count();
    foreach (var item in query)
    {
        i++;
        string tableNumber = item.TableNumber.HasValue ? item.TableNumber.Value.ToString() : "";
        ListViewItem newItem = new ListViewItem(new string[] { i.ToString(), 
                               item.FactorType.ToString(), 
                               item.FactorNumber.ToString(),
                               tableNumber.ToString(),
                               item.Price.ToString(), 
                               DateTime.Now.ToString() });
        newItem.Font = new Font("Tahoma", 12);
        newItem.Name = "Item" + i.ToString();
    
        listView1.Items.Add(newItem);//Exception
    }
    
    void listView1_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
    {
        e.Item = new ListViewItem(e.ItemIndex.ToString());
    }
    The Exception :
    Code:
    When the ListView is in virtual mode, you cannot add items to the ListView items collection. Use  the VirtualListSize property instead to change the size of the ListView items collection.
    Would you please guide me ?
    Thanks.
    Last edited by M-Dayyan; January 16th, 2010 at 06:30 AM.

Tags for this Thread

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center