• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1415
  • Last Modified:

VB.NET ListView - Select first item

Anybody knows how to select the first top item displayed on a listview once sorted by alpha without having to loop through all the items and compare again?

note: ListView1.Items(0).Selected won't work here...
0
ourman
Asked:
ourman
1 Solution
 
DarthPedroCommented:
Why won't that line of code work?  I just tried it, and it seemed to do the job.  I started by adding a list of items into the ListView.  Then sorting them when the column header was clicked, like this:

    private void listView1_ColumnClick(object sender, System.Windows.Forms.ColumnClickEventArgs e)
    {
        listView1.Sorting = SortOrder.Ascending;
        listView1.Items[0].Selected = true;
    }

The first item in the sorted list was selected...
0
 
ourmanAuthor Commented:
A typical idiot's question: I was selecting the item before sorting the listview.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now