Solved

Keeping list view item selected

Posted on 2003-11-27
2
919 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
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

706 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

17 Experts available now in Live!

Get 1:1 Help Now