How can I remove the selection border on a ListViewItem

后端 未结 6 2174
粉色の甜心
粉色の甜心 2020-12-17 22:04

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 selec

6条回答
  •  半阙折子戏
    2020-12-17 22:28

    I know this is rather old, and Windows Forms is antiquated now, but it's still in use and it's still an issue. Worse, none of these solution are elegant, and some don't even work at all.

    Here's a very simple solution, when you create your own control that inherits the ListView, then just override the WndProc to never allow focus. It gets rid of all focus-related dotted selection boxes, item selection, subitem selection, etc...

    using System.Windows.Forms;
    
    public partial class NoSelectionListView : ListView
    {
        public NoSelectionListView()
        {
            InitializeComponent();
        }
    
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == 0x0007) //WM_SETFOCUS
            {
                return;
            }
            base.WndProc(ref m);
        }
    }
    

提交回复
热议问题