I am using LIstView control in virtual mode with the property listView.VirtualMode=True and I have subscribed the event listView1_RetrieveVirtualItem(). But this event is being called many times for each item. What is the reason or How can I prevent RetrieveVirtualItem() from executing many times?
Please check the below code.

public class Form1 : Form
{
    public Form1()
    {
        listView1.VirtualMode = true;
        listView1.VirtualListSize = 100000;

        listView1.RetrieveVirtualItem += new RetrieveVirtualItemEventHandler(listView1_RetrieveVirtualItem);

    }

    private void listView1_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
    {
            ListViewItem itm=new ListViewItem(comboBOx.Items[e.ItemIndex].ToString());
            e.Item = itm;

        // For each visibile item this code is executed many time.
    }    
}

Every time you need to acces to a listview ítem, the virtual retriever is called, as many times as needed, to obtain the virtual ítems collection for the purpose of the current action being done.
See this info from the library.

Hope this helps

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.