Developer, Former MVP, now at Microsoft - Best of 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013
"[HideSelection] controls whether the current sub-selection is visibly hidden when the control loses focus. Most controls highlight the currently selected contained item and make its background color the selection color. If this property were set to True, then the background color would revert to normal when the control loses focus."
' VB Protected Overrides Sub OnGotFocus(ByVal e As System.EventArgs) MyBase.OnGotFocus(e) Static doneOnce As Boolean If Not TreeView1 Is Nothing Then TreeView1.Focus() If doneOnce = False Then doneOnce = True Dim hWnd As IntPtr = Win32Api.GetFocus() Dim lS As Int32 = Win32Api.GetWindowLong(hWnd, -16) lS = lS Or &H20 Win32Api.SetWindowLong(hWnd, -16, lS) End If End If End Sub // C# private bool doneOnce; protected override void OnGotFocus(System.EventArgs e) { base.OnGotFocus(e); if (TreeView1 != null){ TreeView1.Focus(); if (doneOnce == false){ doneOnce = true; IntPtr hWnd= Win32Api.GetFocus(); Int32 lS = Win32Api.GetWindowLong(hWnd, -16); lS = lS | 0x20; Win32Api.SetWindowLong(hWnd, -16, lS); } } }