Question

In our application we had a property grid that the user uses to edit some data, I was told that a property grid that the user could tab through would be most helpful. So I created a property grid that the user could tab through all of the data. The problem is, after they've tabbed through all of the data, I want the next tab press to go to the next control in the tab order.

The property grid is in the middle of the tab order. I have tried to tweak the solution found here: Validate Textbox Text and Increase the Tab Order Once, but have had no luck.

Code for How Tab is handled in Property Grid:

    protected override bool ProcessKeyPreview(ref Message m)
    {
        int wParam = m.WParam.ToInt32();

        switch (m.Msg)
        {
            case WM_KEYDOWN:
                {
                    if (wParam == SHIFT)
                    {
                        isShiftDown = true;
                        return true;
                    }
                }
                break;

            case WM_KEYUP:
                {
                    if (wParam == TAB)
                    {
                        moveSelectedGridItem(!isShiftDown);
                        return true;
                    }
                    else if (wParam == SHIFT)
                    {
                        isShiftDown = false;
                        return true;
                    }
                }
                break;
        }

        return ProcessKeyEventArgs(ref m);
    }
Was it helpful?

Solution

I have tried a workaround and go through it and revert me if you have any concerns.

protected override bool ProcessKeyPreview(ref Message m) { int wParam = m.WParam.ToInt32();

    switch (m.Msg)
    {
        case WM_KEYDOWN:
            {
                if (wParam == SHIFT)
                {
                    isShiftDown = true;
                    return true;
                }
            }
            break;

        case WM_KEYUP:
            {
                if (wParam == TAB)
                {
                    bool ismoved = moveSelectedGridItem(!isShiftDown);

                     // First: modify the method "moveSelectedGridItem" to return bool value (if grid moved: true, if TAB pressed after last grid item: false)

                    if(!ismoved)
                        // handle your implementaion here

                    return true;
                }
                else if (wParam == SHIFT)
                {
                    isShiftDown = false;
                    return true;
                }
            }
            break;
    }

    return ProcessKeyEventArgs(ref m);
}

OTHER TIPS

I think that the behavior you've described is not the standard behavior for a WinForm control, usually the user have to press ESC before iterating to the next control if the cursors is "inside" a control that handles the TAB. Otherwise you have to implement something like RaiseSomeEventToParentControl that I don't think is possible or suggested.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top