Bug in listview in VirtualMode windows Forms  
Author Message
Castro





PostPosted: Visual C# General, Bug in listview in VirtualMode windows Forms Top

I want to create a listview in Windows Forms 2.0 with virtual mode. It works fine except a real bug. When I click an item in the listview in the event

private void listView1_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)

{

}

the e.ItemIndex is the number of VirtualListSize - 1 which in my case is 547. So VirtualListSize is 548 and the e.ItemIndex is 547.

this is happening when I click any item in the listview like 2 or 3 or 12.

What's happening



Visual C#6  
 
 
Peter Ritchie





PostPosted: Visual C# General, Bug in listview in VirtualMode windows Forms Top

The ListView will raise the RetreiveVirtualItem whenever it thinks it needs information about a particular item. There's lots of notifications Windows will send to a ListView to get information about an item, which may be about an item that is not visible.

Why is this a problem

 
 
Castro





PostPosted: Visual C# General, Bug in listview in VirtualMode windows Forms Top

It is a problem because:

1. The ItemIndex of the listview that I clicked is not the one that is comming in RetreiveVirtualItem

2. I use a Hashtable as a cache so that the listview will take its items in RetreiveVirtualItem event from the hashtable. So If I click item 12 for example and in the RetreiveVirtualItem event the e.ItemIndex is the last one (not correct) than my code will try yo get the last element from the HashTable and put it into the listview (hich is wrong)

3. The Hashtable mentioned above doesn't contain all the items from the Database Table. It will execute a sql query every that gets the next set of data from the db table when it is needed to be displayed in the listview so this will be done in the RetreiveVirtualItem event.

Can I use another event of the listview that fires when the listview needs to display an item (Remember that the listview is in virtual mode so it doesn't have all items "bound" to it. Also the HashTable that contains items that will be put into the hashtable is used as a cache and also doesn't contain all db info).