Reload HostWindow data

4 posts, 1 answers
  1. Aditya
    Aditya avatar
    3 posts
    Member since:
    Oct 2011

    Posted 08 Mar 2012 Link to this post

    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.  
  2. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 13 Mar 2012 Link to this post

    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 >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Aditya
    Aditya avatar
    3 posts
    Member since:
    Oct 2011

    Posted 13 Mar 2012 Link to this post

    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.
  5. Answer
    Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 16 Mar 2012 Link to this post

    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 >>
Back to Top