views:

59

answers:

1

Hello.

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.

+1  A: 

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.

deltreme
thanx alot ! Works like a charm. You are the man :)
no9