views:

214

answers:

3

I'm using SetWindowTheme and SendMessage to make a .net listview look like a vista style listview, but the .net control still has a dotted selection border around the selected item:

http://www.bhslaughter.com/Telanor/listview.png

Selected items in the explorer listview don't have that border around them. How can I remove it?

Windows Explorer:

alt text

+1  A: 

Does setting the ListView.ShowFocusCues property to false help?

Josh Einstein
It seems that this property is set to false by default.
Ucodia
While the ShowFocusCues itself didn't work, the WM_CHANGEUISTATE listed on that MSDN page led me to the right answer. By sending a WM_CHANGEUISTATE message with UISF_HIDEFOCUS I was able to get rid of the focus rectangle.
Telanor
+1  A: 

It does not seem that there is a particular way to change ListViewItem styles using Windows Forms.

Sometimes there is no way to change some Win32 control behaviors using managed code. The only way is to do some P/Invoke to modify specific behaviors. I find this really tricky but you have no other choice. I often faced this situation when developing Windows Mobile UIs (justly with ListView).

So I have no direct answer to your question but I am pretty sure that if it is not possible using Windows Forms, you can surely do with P/Invoke. The only clues I can give you:

Ucodia
+1  A: 

Setting the HotTracking property to true hides the focus rectangle. This repro-ed the Explorer style on my Win7 machine:

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

class MyListView : ListView {
  public MyListView() {
    this.HotTracking = true;
  }
  protected override void OnHandleCreated(EventArgs e) {
    base.OnHandleCreated(e);
    SetWindowTheme(this.Handle, "explorer", null);
  }
  [DllImport("uxtheme.dll", CharSet = CharSet.Auto)]
  public extern static int SetWindowTheme(IntPtr hWnd, string appname, string subidlist);
}

Beware that getting the items underlined is a side-effect.

Hans Passant