Creating a control in code

When you use drag-and-drop to add a DataWindow control to a form, the control is added to the form’s control collection and a handle is created for it automatically. When you create a DataWindow programmatically, you need to force a handle to be created for the control and any child controls before you can access the control. Calling the control’s constructor does not create the handle. You can use the CreateControl method to create a handle for the DataWindow control.

The following code creates an instance of a DataWindowControl called dwC, sets its library list and DataWindow object, creates a handle for dwC, sets the location and size of the control, and add it to the form’s controls collection:

[Visual Basic]
Dim dwC As Sybase.DataWindow.DataWindowControl
' ...
dwC = New Sybase.DataWindow.DataWindowControl
dwC.LibraryList = "C:\mypbls\employee.pbl"
dwC.DataWindowObject = "d_emp"
dwC.Location = New System.Drawing.Point(32, 24)
dwC.Size = New System.Drawing.Size(272, 152)

dwC.CreateControl()
me.Controls.Add(dwC)

[C#]
private Sybase.DataWindow.DataWindowControl dwC;
// ...
dwC = New Sybase.DataWindow.DataWindowControl();
dwC.LibraryList = "C:\\mypbls\\employee.pbl";
dwC.DataWindowObject = "d_emp";
dwC.Location = new System.Drawing.Point(32, 24);
dwC.Size = new System.Drawing.Size(272, 152);

dwC.CreateControl()
this.Controls.Add(dwC);;

NoteDataWindow controls on tab pages In a TabControl, if a DataWindow control is on one of the tab pages that is hidden when the TabControl first displays, you need to set its Transaction object and retrieve data when the tab page displays. For more information, see “Retrieving data into DataWindow controls on tab pages”.