c# - Waiting for Controls to be Initialized -


My form looks like a three-pane email client There is a grid with the list of people on the left. Extension record

[x] cooking [x] window cleaning [x] brain surgery

[x]] massage therapy [x] random acts of vandalism [Singing]

When the form is opened, the first person listed in the grid on the left side of the Focus Form goes to the person, and Distributing the Foks_oar_aitiwd event fires. For this event, I get the ID of the existing person in the handler, then receives detailed data from that database for that person and populates the records of the extension, and also receives the specialty rows of the person's area and the checkbox It all works well, when the form is opened first, because the custom control with many checkboxes has not yet started. MyCustomControl is empty at that time.

  if (null! = MyCustomControl) {MyCustomControl.SetCheckedValues ​​(data source); }   

What is the best practice design to deal with this situation? What do I do when my control has not started completely yet?

  if (null! = MyCustomControl) {MyCustomControl.SetCheckedValues ​​(Datasheet); } other { // ?? Wait for a while and try every 100ms? }    

By implementing the way I have solved this problem in my own control for .

In your control, you will put something like this:

  Public class MyCustomControl: ISupportInitialize {private bool_initializing = false; Private Zero BeginInit () {_initializing = true; } Private Zero EndInit () {_initializing = false; } Private Zero Some Mathematical RightsAnventDuring () {returns (_incibling) returns; // ...}}   

The Windows Designer checks for your control to implement the interface, and this code will be . Designer.cs builds in the file:

  ((System.ComponentModel.ISupportInitialize) (this.customControl1)). BeginInit (); ///////ContentControl1///.CustomControl1.SelectedIndex = 0; // This will normally increase the event (System.ComponentModel.ISupportInitialize) (this.customControl1)). EndInit ();    

Comments