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

Reload HostWindow data

3 Answers 109 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Aditya
Top achievements
Rank 1
Aditya asked on 08 Mar 2012, 05:51 PM
Hello,

I was wondering if anyone has any experience reloading a HostWindow.  I can get the HostWindows I need from my DockWindows, gather the info I need from it, close the the HostWindow, make my new calculations, create a new HostWindow and add it to the Dock.  However, this just puts the new HostWindow on the most recent document that had focus.  What I want is for the new HostWindow to show up/refresh in the same spot.  Does anyone know if this is possible?  

This is what I was thinking; but it leaves the old HostWindow in the Dock and does not seem to add the "new" HostWindow to the dock.
//set the current window to a host window, if not a host window will return null
HostWindow hw = this.dockMain.DockWindows[i] as HostWindow;
 
//creates new form in hostwindow
hw = new HostWindow(createRightForm(tempModel, formName));

If you need anymore info from me just let me know.  Thanks.  

3 Answers, 1 is accepted

Sort by
0
Julian Benkov
Telerik team
answered on 13 Mar 2012, 10:16 AM
Hello Aditya,

The best solution in this case is just to replace the content of the current HostWindow:

//set the current window to a host window, if not a host window will return null
HostWindow hw = this.dockMain.DockWindows[i] as HostWindow;
Form form = createRightForm(tempModel, formName);
form.TopLevel = false;
form.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
form.Dock = DockStyle.Fill;
hw.Controls.Clear();
hw.Controls.Add(form);

I hope this helps. Let me know if you need further assistance.

Regards,
Julian Benkov
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Aditya
Top achievements
Rank 1
answered on 13 Mar 2012, 03:43 PM
Hi Julian,

Thanks for the response.  However, I attempted your code but it seems to close the host window; I am not sure why.  Here is my code (I removed some of the commented out/old code): 

//re-run model
        private void miRunModel_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
 
            int modelID = (int)currentNode.Value;
 
            Model tempModel = modelList.Where(d => d.modelID == modelID).FirstOrDefault();
             
            tempModel.getSignals();
 
            string selModelName = tempModel.modelName;
 
            //go through # of windows
            for (int i = 0; i < this.dockMain.DockWindows.Count; i++)
            {
                //set the current window to a host window, if not a host window will return null
                HostWindow hw = this.dockMain.DockWindows[i] as HostWindow;
                 
                if (hw != null)
                {
                    //split text of host window to get model and form type
                    string[] hwText = hw.Text.Split(':');
                    string modelName = hwText[0];
                    string formName = hwText[1].Trim();
 
                    //check if model names are the same
                    if (selModelName == modelName)
                    {
                        Form newForm = createRightForm(tempModel, formName);
 
                        newForm.TopLevel = false;
                        newForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
                        newForm.Dock = DockStyle.Fill;
 
                        hw.Controls.Clear();
                        hw.Controls.Add(newForm);
                    }
                }
            }
            Cursor = Cursors.Arrow;
        }

Let me know if I am doing something wrong.  Thanks.
0
Accepted
Julian Benkov
Telerik team
answered on 16 Mar 2012, 09:57 AM
Hi Aditya,

The only missing code in this situation is Show() method of newly created Form:

private void miRunModel_Click(object sender, EventArgs e)
{
    Cursor = Cursors.WaitCursor;
 
    int modelID = (int)currentNode.Value;
 
    Model tempModel = modelList.Where(d => d.modelID == modelID).FirstOrDefault();
 
    tempModel.getSignals();
 
    string selModelName = tempModel.modelName;
 
    //go through # of windows
    for (int i = 0; i < this.dockMain.DockWindows.Count; i++)
    {
    //set the current window to a host window, if not a host window will return null
    HostWindow hw = this.dockMain.DockWindows[i] as HostWindow;
 
    if (hw != null)
    {
        //split text of host window to get model and form type
        string[] hwText = hw.Text.Split(':');
        string modelName = hwText[0];
        string formName = hwText[1].Trim();
 
        //check if model names are the same
        if (selModelName == modelName)
        {
        Form newForm = createRightForm(tempModel, formName);
 
        newForm.TopLevel = false;
        newForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
        newForm.Dock = DockStyle.Fill;
 
        hw.Controls.Clear();
        hw.Controls.Add(newForm);
        newForm.Show();
        }
    }
    }
    Cursor = Cursors.Arrow;
}

If you continue to experience the same issue, please send me a sample project with your settings to investigate it locally. Please note that you have to open a new support ticket in order to be able to attach your files.

Thank you for your cooperation. 

Greetings,
Julian Benkov
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Tags
Dock
Asked by
Aditya
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
Aditya
Top achievements
Rank 1
Share this question
or