Click here to Skip to main content
15,891,682 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello there, I am trying to figure out how to refresh a user control, I have tried UserControl1.Refresh(); but it seems that it not doing anything. I need it so it refresh the listviews inside each usercontrol which is a total of 9.

What be the best possible method around this.

Thanks in advance.

Example of my coding

  private void refreshTheme()
        {
            /*
             uc_advancedWarfare.Invalidate();
             uc_blackOps.Invalidate();
             uc_blackOps2.Invalidate();
            uc_blackOps3.Invalidate();
            uc_ghosts.Invalidate();
            uc_modernWarfare2.Invalidate();
            uc_modernWarfare3.Invalidate();
            uc_mw.Invalidate();
            uc_waw.Invalidate();
            */

/*
             uc_advancedWarfare.Refresh();
             uc_blackOps.Refresh();
             uc_blackOps2.Refresh();
            uc_blackOps3.Refresh();
            uc_ghosts.Refresh();
            uc_modernWarfare2.Refresh();
            uc_modernWarfare3.Refresh();
            uc_mw.Refresh();
            uc_waw.Refresh();
            */



            //this.Refresh();
            var controls = new UserControl[]
            {
                this.uc_advancedWarfare,
                this.uc_blackOps,
                this.uc_blackOps2,
                this.uc_blackOps3,
                this.uc_ghosts,
                this.uc_modernWarfare2,
                this.uc_modernWarfare3,
                this.uc_mw,
                this.uc_waw
            };

            foreach (var uc in controls)
            {
                if (uc == null)
                    continue;

                uc.BackColor = this.BackColor;
            }
        }


What I have tried:

I have only tried the following

UserControl1.Refresh();
UserControl1.Invalidate();
Posted
Updated 18-Jun-18 20:54pm
v3

Try
C#
MyUserControl.Invalidate();
UserControl.Invalidate Method (System.Windows.Forms)[^]
 
Share this answer
 
Comments
Member 13199106 19-Jun-18 2:06am    
Sadly that didn't work bud, but thanks for trying.
Maciej Los 19-Jun-18 2:27am    
Sadly? You have to explain why it doesn't work for you...
Member 13199106 19-Jun-18 2:37am    
It does nothing like Refresh does nothing.
OriginalGriff 19-Jun-18 3:06am    
It forces a repaint of the entire control: if you want it to do something else, then you need to explain exactly what you expect a "refresh" to do!
Maciej Los 19-Jun-18 2:27am    
5ed!
I'm pretty sure that you have to read this: c# - UserControl Invalidate() method. How to properly invalidate the child controls in a UserControl?[^]

Note:
You didn't explain what's wrong with invalidate method, but i guess, nested controls of UserControl aren't invalidated.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900