Questions about some designer code in c# csharp .net

I wanted to create a DataGridView dynamically, and I did so by basically copying most of the designer code.

While doing it I noticed some lines of code that I frankly don't really understand.

Can someone please explain to me what these 3 things do and why? Thanks!


// 1) BeginInit & EndInit
((System.ComponentModel.ISupportInitialize)(this.dgvFile)).BeginInit(); 
((System.ComponentModel.ISupportInitialize)(this.dgvFile)).EndInit();
 
// 2) Resume and Suspend Layout (If 'this' refers to a form,
//    do I need to suspend it if I am not modifying it but
//    only a control within it, so I suspend only that control?)
dgvFile.SuspendLayout(); this.SuspendLayout();
dgvFile.ResumeLayout(false); this.ResumeLayout(false);
 // dgvFile is my DataGridView
 
// 3) this.PerformLayout()?

Open in new window

yaronusaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Cedric_DCommented:
These blocks used like "cache":

when you issue for ex. several operations, which both cause control's redraw, you will see flicker on the screen.
Include them inside suspendLayout/ResumeLayout  block and it will both remove flicker and increase performance (redraw will be only once at ResumeLayout).

while BeginInit/EndInit used only at initialization of control and its child controls,
BeginLayout/EndLayout can be used through whole control's lifecycle, for example inside event handlers.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
yaronusaAuthor Commented:
You said: "while BeginInit/EndInit used only at initialization of control and its child controls,
BeginLayout/EndLayout can be used through whole control's lifecycle"

Above, are you saying that: although Beg/EndInit is used by the designer at initialization, we can use it later on at runtime?
0
yaronusaAuthor Commented:
Ok, thanks for those answers, but I didn't see this part of my questions answered:

"If 'this' refers to a form, do I need to suspend it if I am not modifying it but
 only a control within it, so I suspend only that control?"

In other words, do I need to suspend the container of a control or just the control in order
for the suspension to be effective?
0
Cedric_DCommented:
You can suspend any of it, even can suspend no one - this depends on how much you gain with this suspension, for ex.

suspend a form
  -- modify child control 1
  -- modify child control 2
resume form

or

suspend a control
  -- modify some control's property
  -- modify some control's property
resume a control

in my humble opinion, general measure is a count of enclosed operations for necessity of these blocks.
0
yaronusaAuthor Commented:
Thanks for your help!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.