Vista Treeview and Listview


Update: Please note I have an update to this post available here.

Standard windows forms tree and listview controls look rather dated on Vista, with a blue background to indicate a selected node or item

before

It is very easy to update both these controls to have the vista look and feel with three lines of code by calling the SetWindowsTheme method. This is ignored on XP so adding this code will not affect the same application running on XP.

after

C#

using System;

using System.Runtime.InteropServices;

using System.Windows.Forms;

namespace VistaTheme

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

SetWindowTheme(treeView1.Handle, “explorer”, null);

SetWindowTheme(listView1.Handle, “explorer”, null);

}

[DllImport(“uxtheme.dll”, CharSet = CharSet.Unicode, ExactSpelling = true)]

private static extern int SetWindowTheme(IntPtr hWnd, string appName, string partList);

private void Form1_Load(object sender, EventArgs e)

{

treeView1.ExpandAll();

}

}

}

Visual Basic

Imports System.Runtime.InteropServices

Public Class Form1

<DllImport(“uxtheme.dll”, CharSet:=CharSet.Unicode, ExactSpelling:=True)> _

Private Shared Function SetWindowTheme(ByVal hWnd As IntPtr, ByVal appName As String, ByVal partList As String) As Integer

End Function

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

SetWindowTheme(treeView1.Handle, “explorer”, Nothing)

SetWindowTheme(listView1.Handle, “explorer”, Nothing)

treeView1.ExpandAll()

End Sub

End Class

3 thoughts on “Vista Treeview and Listview

  1. Hello

    My name is Ricardo Boaro, I work for http://WWW.MRBOOL.COM as a technical editor. I would like to invite you to join our team of video classes producers.

    Currently we need speakers (producers) for Java, .Net, Asp.Net and Delphi videos, but we are accepting suggestions if you know any other language.

    Let me explain how it works

    • Each video class must have at least fifteen minutes .
    • The program that we use to record the video classes is Camtasia Studio.
    • The payment for each video class sent, approved and published is US$ 80,00 (eighty dollars)
    • The payment is done until the fifteenth day of the next month after the publishing
    • THE PAYMENT IS POSSIBLE PAY TO YOU FOR THIS FORM PAYPAL

    We would be pleased if you join our team. If you have any question or doubt, just get in touch with me.

    My e-mail rboaro@devmedia.com.br
    Regards,

  2. Pingback: Disabling windows themes for controls « Castalian

  3. Pingback: Windows 7 TreeView and ListView « Castalian

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s