Specifying the DataWindow object at runtime

When you associate a DataWindow object with a control on a form, you are setting the initial value of the DataWindow control's DataWindowObject property. At runtime, this tells your application to create an instance of the DataWindow object specified in the control's DataWindowObject property and use it in the control.

Setting the DataWindowObject property in code

In addition to specifying the DataWindow object in the Properties window, you can switch the object that displays in the control at runtime by changing the value of the DataWindowObject property in code.

When you change the DataWindow object at runtime, you might need to call SetTransaction again. For more information about using these methods, see “Associating the Transaction object with a DataWindow control or DataStore” and “Associating the AdoTransaction object with a DataWindow control or DataStore”.

For example: to display the DataWindow object d_EmpHist from the library C:\emp.pbl in the DataWindow control dwEmp, you can code:

dwEmp.LibraryList = "c:\emp.pbl"
dwEmp.DataWindowObject = "d_EmpHist"

NoteCode examples Simple code examples, where the only difference between Visual Basic and C# statements is the addition of a semicolon for C#, are shown in Visual Basic.

The DataWindow object d_EmpHist was created in DataWindow Designer and is stored in a library that is on the control’s library list so that you can see it in the control at design time.

NoteHow the DataWindow object is found at runtime At runtime, the DataWindow server strips the full path from each library and looks for the library in the system path. If you have more than one copy of a library, one in the path specified in the library list and one in the system path, you might see unexpected results when you run or debug the application if the DataWindow exists in only one version of the library or has been modified in only one version.

The control dwEmp is contained on the form and is saved as part of the form.

Getting a list of DataWindow objects in a library

The GetDataWindowObjectEntries method in the Utility class lists the DataWindow objects present in a given PBL or PBD. The method takes a library name as an argument and returns an array of DataWindowObjectEntry objects, each of which holds the name of a DataWindow object as well as its last-modified date and comments.

This C# code in the Page_Load event populates the dwList drop-down list box with a list of the DataWindow objects in the library list:

if (!IsPostBack)
{
   Sybase.DataWindow.DataWindowObjectEntry[] dws;
   dws = Sybase.DataWindow.Utility.
      GetDataWindowObjectEntries(Page.MapPath
      (wdw.LibraryList));
   for (int i=0; i<dws.Length; i++)
      dwList.Items.Add(new ListItem(dws[i].Name,
         dws[i].Name));
}