• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 102
  • Last Modified:

C# Refresh main form with Infragistic Control from another form

When my main form (winform) loads it is using an infragistics control.  I'm using Tiles.  A user clicks on a tile and navigates to a windows form.  The user is allowed to add data which is stored in an XML document.  When the user does this I need to refresh the main form to add new tiles to the main form.

Any idea how to do this from another winform?
0
CipherIS
Asked:
CipherIS
1 Solution
 
Daniel Van Der WerkenIndependent ConsultantCommented:
Okay. I think this is a generic way for you to work this out.

Expose a public method on the first winform as I'm showing here:

    public partial class Form1 : Form
    {
        public void DoSomething()
        {
            GroupBox gb = (GroupBox)Controls.Find("form1GroupBox1", true).FirstOrDefault();

            if (gb != null)
            {
                CheckBox cb = new CheckBox();
                cb.Name = "My New Checkbox";
                cb.Text = "Some awesome checkbox";
                cb.Checked = true;

                gb.Controls.Add(cb);
            }
        }

        public Form1()
        {
            InitializeComponent();


        }

        private void btnNewForm_Click(object sender, EventArgs e)
        {
            Form2 form2 = new Form2();
            form2.Show();
        }
    }

Open in new window


Then, on the second form, you need to grab hold of the first form and call it.

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

        private void btnAddControl_Click(object sender, EventArgs e)
        {
            FormCollection fc = Application.OpenForms;
            
            foreach(var f in fc)
            {
               if (f.GetType() == typeof(Form1))
                {
                    Form1 form = (Form1)f;
                    form.DoSomething();
                }
            }
        }
    }

Open in new window


Form1 had a button and a group box. Form2 just had a button. I dynamically added a control to Form1 as shown.

You should be able to do something similar to this very thing that I'm showing with what you're looking to do.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now