Link to home
Start Free TrialLog in
Avatar of yaronusa
yaronusa

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of Cedric_D
Cedric_D

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of yaronusa
yaronusa

ASKER

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?
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?
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.
Thanks for your help!