Solved

Keeping list view item selected

Posted on 2003-11-27
2
959 Views
Last Modified: 2008-02-01
Is there a way to keep a list view item selected graphically (with the blue highlight) even when the listview does not have the focus?
0
Comment
Question by:jjacksn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 6

Expert Comment

by:DaniPro
ID: 9835734
You can use the SelectedIndexChanged Event for change the listviewitem color (if you use the multiselect option you must change the foreach loop):

private void listView1_SelectedIndexChanged(object sender, System.EventArgs e)
{
      foreach (ListViewItem lvi in listView1.Items)//listView1.SelectedItems)
      {
            lvi.BackColor = System.Drawing.SystemColors.Info;
            lvi.ForeColor = System.Drawing.SystemColors.InfoText;
      }
      listView1.FocusedItem.BackColor = System.Drawing.SystemColors.Highlight;
      listView1.FocusedItem.ForeColor = System.Drawing.SystemColors.HighlightText;                  
}
0
 
LVL 1

Accepted Solution

by:
AJMartin earned 250 total points
ID: 9835787
Set the property:
 HideSelection
to false and your problem will be solved.

Quoted from .NET Framework SDK Documentation:
Property Value [is] true if the selected item does not appear highlighted when the control loses focus; false if the selected item still appears highlighted when the control loses focus. The default is true.

Remarks
When this property is set to false, selected items in the ListView control remain highlighted in a different color than the current selection color specified by the operating system when the ListView control loses focus. You can use this property to keep items that are selected by the user visible when the user clicks a different control on the form or moves to a different window.

I hope that helps!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

734 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