Change background color for listview?

How to change highlight color in ListView? By default, when the user selects an item, it shows a blue background. I want to change this to dark gray or something else ... Thanks for the help!

+6
c # colors listview winforms selection
source share
3 answers

ObjectListView - a wrapper around WinForm ListView - has properties that allow you to control the background and foreground color of selected rows. He uses the technique proposed by Obalix, but it has already done the hard work for you.

So, with a little effort, you can create something like this:

alt text

The line "Feel Good Inc" shows the custom foreground and background for the selection.

+1
source share

If you want your ListView have a Windows ListView Explorer style (including a nice rounded look in Win7 / Vista), you could use a little P / Invoke to do this:

 [DllImport("uxtheme.dll", CharSet = CharSet.Unicode, ExactSpelling = true)] internal static extern int SetWindowTheme(IntPtr hWnd, string appName, string partList); // You can subclass ListView and override this method protected override void OnHandleCreated(EventArgs e) { base.OnHandleCreated(e); SetWindowTheme(this.Handle, "explorer", null); } 
+7
source share

Good for WinForms, you need to set the OwnerDraw property to true, and then use the DrawItem and DrawSubItem to draw the item manually.

See here for an example.

+2
source share

All Articles