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!
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()?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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?
"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.
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.
ASKER
Thanks for your help!
ASKER
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?