Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
In what method to get data and bind controls?
Message
From
17/01/2010 11:30:05
 
General information
Forum:
ASP.NET
Category:
Forms
Environment versions
Environment:
C# 2.0
Miscellaneous
Thread ID:
01444346
Message ID:
01444400
Views:
26
>>>Hi,
>>>
>>>Where do you recommend to make a call to initialize BIZ (typed data set), fill it, and bind controls to the Binding Source? I am reading a book where the examples they have are always in method OnFormLoad. In my tests I use method of the same name as the form class (do I understand correctly that this is equivalent to INIT of VFP?). What is better, OnFormLoad or INIT?
>>
>>Hi,
>>First : There is no WinForms INIT - you probably mean the constructor? Neither is there a OnFormLoad() method - again you probably meant OnLoad() ?
>>
>>Putting the data access code in the contstructor *after* the InitializeComponent() call should be OK - but overriding the OnLoad method is the recommended option. The base OnLoad() method is where the form actually raises the Load event so you could use:
protected override void OnLoad(EventArgs e)
>>{
>>       LoadData()
>>       base.OnLoad(e);
>>}
You could swap the two statements around - but be aware of the subtle difference since any active Load event handlers will be called by the base.OnLoad(e) line and whether your data will be available at that point will depend on the order of those two statements.....
>
>Thank you for clarifying the INIT and Constructor question.
>
>And thank you for the suggestion to use OnLoad method. The book I am reading has method names OnFormLoad but the author could have simply decided to change the name of the default method (it is possible, right?).

No. Maybe it's his own method and he's calling it from elsewhere or has it wired up to the Load event? If you use OnLoad you are overriding the base Form.OnLoad() method.
>
>As to your third point to the order of calling LoadData() and base.OnLoad(e), could you please clarify something? If the form is based on the default Win Form why do you need to call base.OnLoad(e)? Is it like DODEFAULT() in VFP?

Pretty much - 'base' refers to the parent class. If you override OnLoad() and don't call the base implementation then the Load event won't be fired. i.e if you could see inside the Form.OnLoad() method it would probably look like this:
public virtual OnLoad(EventArgs e)
{
    if (Load != null)
      Load(this,e);
}
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform