简体   繁体   中英

how to programmatically display the bottom row in virtual ListView

I have a virtual ListView in Winforms which nicely displays the contents from a database. Items get asynchronously added to the database and are visible when I pull the scrollbar to the bottom.

Now I would like to insure that whenever the asynchronous thread adds to the database it also updates the ListView so that it knows which index should be the bottom row. Before I added the ListView object, I could do that with a ListBox where I set which index should be the top index, based on itemheight and listbox height:

int numItems = listBox1.ClientSize.Height / listBox1.ItemHeight;
if (listBox1.TopIndex == listBox1.Items.Count - numItems - 1)
    listBox1.TopIndex = listBox1.Items.Count - numItems + 1;

Unfortunately neither ItemHeight nor TopIndex exist in ListView.

But the major question is: How do I tell the virtual ListView that it should display a specific range of indexes - or insure that some index gets displayed?

You can use the property TopItem to set the top visible item in the ListView (no matter it's in virtual mode or not):

listView1.TopItem = listView1.Items[itemIndex];//itemIndex is the index of the item 
//you want to make visible as the top item.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM