To add items to the schedule control you need to do something like this:
DataStore ids_schedule
DateTime ldt_start
Long ll_row, ll_rows, ll_length
String ls_display, ls_key
// ... Retrieve all the schedule items you want to use into the DataStore. Then ...
ll_rows = ids_schedule.RowCount()
FOR ll_row = 1 TO ll_rows
// The key must be a string value, if your IDs are numeric, just convert it to a string.
ls_key = ids_schedule.GetItemString(ll_row, "schedule_id")
ldt_start = ids_schedule.GetItemDateTime(ll_row, "start_dt")
// If you use end dates and times rather than length, you will need to calculate the length
ll_length = <length of appointment in minutes>
ls_display = ids_schedule.GetItemString(ll_row, "description")
// The following are optional depending on whether you want to show resources
// or categories in the schedule.
ls_resource = ""
ls_category = ""
// Add the schedule item.
ole_schedule.Object.ScheduleItems.Add(ls_key, ldt_start, ls_resource, ldt_start, ll_length, ls_display, ls_category)
NEXT
Once the schedule items are added, there are a whole series of events that can be triggered on the schedule control as users move and resize schedule items, such as beforemove, beforeitemresize, beforedelete, aftermove, etc. Each schedule item in the schedule control is an oleobject in PowerBuilder. Some events have an argument that returns a reference to the schedule item itself and some only give an index to a schedule item. To get the schedule OLEObject using the index, do the following:
OLEObject lole_item
lole_item = ole_schedule.Object.ScheduleItems[index]
Once you have the schedule item OLEObject from one of these events, use its properties to add, change, or delete the schedule items in your DataWindow or DataStore. For example:
Long ll_row, ll_length
String ls_key
ls_key = lole_item.Object.Name
ll_row = ids_schedule.Find("schedule_id = ' + ls_key + "'", 1, ids_schedule.RowCount())
// If this is a new item...
IF ll_row = 0 THEN
ll_row = ids_schedule.InsertRow(0)
ids_schedule.SetItem(ll_row, "schedule_id", <new ID>)
// When you create new rows, be sure to update the unique name on the schedule item.
lole_item.Object.Name = ids_schedule.GetItemString(ll_row, "schedule_id")
END IF
// For new or changed items, update the dates and times.
ids_schedule.SetItem(ll_row, "start_dt" = DateTime(lole_item.Object.StartDate)
// Use ll_length set the length in ids_schedule or to calculate the end datetime.
ll_length = Long(lole_item.Object.Length)
// ... etc.
// Or, if the event the schedule item came from was triggered by a delete...
ids_schedule.DeleteRow(ll_row)
Assuming the code above keeps all the rows in the DataStore synchronized with the changes to the schedule items, then all you have to do is update the DataStore to load all the schedule changes into your database:
ids_schedule.Update()