简体   繁体   中英

CF TreeView - Selected Item when control loses focus

I know that "HideSelection" property is missing in CF. But i still need to handle situation when an item is selected that it remains selected (greyed) even when the control looses focus.

I have tried using this peace of code, but with no success. I get an exception in GetFocus() method and i dont know what im doing wrong.

Any help is much appreciated !

[DllImport("User32.dll")]
    static extern IntPtr GetFocus();
    [DllImport("User32.dll")]
    static extern Int32 GetWindowLong(IntPtr hwnd, Int32 integer1);
    [DllImport("User32.dll")]
    static extern IntPtr SetWindowLong(IntPtr hwnd, Int32 integer1, int integer2);

    private bool doneOnce;
    protected override void OnGotFocus(System.EventArgs e)
    {
        base.OnGotFocus(e);
        if (this.itemsTreeView != null)
        {
            this.itemsTreeView.Focus();
            if (doneOnce == false)
            {
                doneOnce = true;
                IntPtr hWnd = GetFocus();
                Int32 lS = GetWindowLong(hWnd, -16);
                lS = lS | 0x20;
                SetWindowLong(hWnd, -16, lS);
            }
        }
    }

I have put this code in my "code behind" view that holds TreeView control.

Windows CE uses coredll.dll instead of user32.dll .

Some functions are equal on both platforms, while some are not implemented for Compact Framework. I usually check http://www.pinvoke.net for the declares.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM