![]() Gravitybox Schedule.NET
1998-2005 Gravitybox Software LLC
Page 49 of 90
Chapter 5
Putting it all together
Overview
Now that you understand where the schedule information resides, you can create some
data. In this section code snippets will demonstrate how to add data at run-time and
display some needed, built-in dialogs.
Adding Appointments
All appointments that are displayed on the schedule are held in the schedules
AppointmentCollection. It has an Add and Remove method so there is no confusion on
how to use the collection.
You may clear the AppointmentsCollection at any time by calling its Clear method.
Schedule1.AppointmentCollection.Clear()
Also adding appointments to the collection is quite easy. The collection is not only an
object that holds a set of appointments but it is also the factory that creates them.
Appointment objects may not be created freely outside of the collection. The
AppointmentCollection creates and destroys all appointments. There is no such thing as
a non-parented appointment. The following code snippet adds a 1-hour appointment on
January 1, 2004 at 8am.
Schedule1.AppointmentCollection.Add("", #1/1/2004#, #8:00:00 AM#, 60)
The Add method creates the appointment and adds it to the collection. It returns a
reference to the newly created object so you may set any of its many properties. Only
the necessary properties are set through the constructor like date, time, and length.
Most of an appointments properties are optional and as such as not set during its
creation. However after creating it you may wish to set its text, color, etc. The first
parameter to the Add method is the appointment key. Notice that it is an empty string.
This tells the collection to create a random key and assign to the appointment. If you are
loading appointments from a database you will most likely set the key so that you may
map the appointment back to its corresponding record in the database. In the code
snippet below an appointment is added and then its Subject property is set.
Dim appointment As Gravitybox.Objects.Appointment
appointment = Schedule1.AppointmentCollection.Add("", _
#1/1/2004#, #8:00:00 AM#, 60)
appointment.Subject = "John Doe"
|