Question

I have a listview that has a Jump function i coded, i wanted the End User to just write the Index in a textbox and click a button and it auto selects the indexed item, and put focus into it, makes the item the Listview "Topitem", this is the button code:

if (toolStripTextBox2.Text != "")
        {
            listView1.Items[Convert.ToInt32(toolStripTextBox2.Text)].Selected = true;
            //listView1.TopItem.Index = Convert.ToInt32(toolStripTextBox2.Text);
        }

I cannot change the Topitem, is there anyway to change the topitem, as in change view position, not change value.

Was it helpful?

Solution

I would use the EnsureVisible method found here. Although this will only scroll the specified item into view, and won't necessarily scroll the item to be the "TopItem" in the list view.

The Remarks section at the above link shows that it may be possible to force an item to the top of the viewable area by calling EnsureVisible twice - the first to ensure it is visible, and the second to force the list view to scroll it to the top.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top