This is a migrated thread and some comments may be shown as answers.

Setting the active MdiChild/DockWindow of a RadDock

2 Answers 370 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Jill-Connie Lorentsen
Top achievements
Rank 1
Jill-Connie Lorentsen asked on 15 Apr 2011, 02:16 PM

I have a RadDock with several MdiChildren/DockWindows. When the user closes one of the tabs I want the focus to be set to the previously active tab.

In the ActiveWindowChanged event I remeber the previous active tab. 

I've tried both the radDock.ActivateMdiChild(Form) and radDock.ActivateWindow(DockWindow) methods

What am I missing?

    bool exists = (Array.IndexOf(radDock.MdiChildren, _currentMdi) != -1);
    if (!exists && _prevMdi != null)
    {
        _currentMdi = null;
        _currentDockWindow = null;
          
        //radDock.ActivateMdiChild(_prevMdi);
        radDock.ActivateWindow(_prevDockWindow);
          
    }
 
_prevMdi = _currentMdi;                   
_currentMdi = (Form) ((HostWindow) e.DockWindow).Content;

_prevDockWindow = _currentDockWindow;
_currentDockWindow = e.DockWindow;

2 Answers, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 20 Apr 2011, 09:30 PM
Hi Jill-Connie Lorentsen,

Please find attached a sample project that follows your requirements. After you close a window, the previously activated window becomes active again. If this is not your requirement, please describe your scenario in greater detail. This will allow me to assist you further.

All the best,
Nikolay
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Trevor
Top achievements
Rank 1
commented on 16 Dec 2023, 12:08 AM

I need the same functionality described in the original post. The solution suggested in this answer works if the user closes forms by clicking the tab's close button, but the it doesn't work if the forms close themselves. FYI, our forms have toolbars with close buttons, so that's what I mean when I say "the forms close themselves".

I've attached a sample project to illustrate the problem. Use the button to add a few forms. Click on a different tab and then close it using the tab's close (x) button. Note that the previously active tab becomes active again. So far so good, the solution is working. Now try the same thing but close the form using the button within the form. Note that the previously active tab is not activated. If you break into code, you'll see that the DockWindowClosed event doesn't even fire in this case.

I've spent some time trying to find a combination of events that work regardless of whether the tab is closed directly or the form is closed directly, but I haven't had any luck. I found that the DockWindowRemoved event fires in both cases, but the previous window doesn't activate because the RadDock is already in the process of applying its default tab activation behaviour. I'm hoping you can help me get this solution working.

Thanks.
0
Dinko | Tech Support Engineer
Telerik team
answered on 20 Dec 2023, 10:05 AM

Hello Jill-Connie Lorentsen,

Thank you for sharing your project.

Indeed, closing the Form directly will not trigger the DockWindowClosed event as the close action is triggered on the inner form. You can workaround this by calling the close method of the Parent which in this case is Telerik.WinControls.UI.Docking.HostWindow.

public partial class Form2 : RadForm
{
    public Form2()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        if (this.Parent != null)
        {
            (this.Parent as Telerik.WinControls.UI.Docking.HostWindow).Close();
        }
    }
}

I hope that this approach will work for you.

Regards,
Dinko | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Dock
Asked by
Jill-Connie Lorentsen
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Dinko | Tech Support Engineer
Telerik team
Share this question
or