Need to SetSelectedItem for a single selection ListView

Posted on 2006-04-01
Last Modified: 2012-05-05

I have a ListView set to single selection.  And when I look for SelectedItem I find a collection called SelectedItems.  How do I assign the value the the ListViewItem of my choice?

Question by:ba272
    LVL 30

    Accepted Solution


    Have you tried:
         lv.Items[index].Selected = true;

    where index is the index of the item to select

    Alex :p
    LVL 18

    Assisted Solution

    by:Ravi Singh
    Hi, to set the selected item you have to set the Selected property of that ListViewItem to true but also then call the Select() method of the ListView, otherwise the selection doesnt occur, so you need something like:

    listView1.Items[index].Selected = true;
    LVL 14

    Assisted Solution

    listView1.SelectedIndex = 0; works also.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
    This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now