You can use the following code to do the following…
Add an appointment to the dbiDayView and it will add it to Office300 on the dbiSchedule
Change the start/end times of an appointment in the dbiDayView and it will be reflected in the dbiSchedule
Move and appointment in dbiDayView and it will move in dbiSchedule
Move a timebar in dbiSchedule and it will be reflected back to the appointment
Change the size of a timebar in dbiSchedule and it will change the appointment in dbiDayView
Dim booleanTimeBarChanged As Boolean = False ' Used so we don't fire a change event when changing dayview via code
Private Sub DbiDayView1_AfterAppointmentAdd(ByVal sender As Object, ByVal e As Dbi.WinControl.DayView.AfterAppointmentAddEventArgs) Handles DbiDayView1.AfterAppointmentAdd
Dim newTimebar As New Dbi.WinControl.Schedule.dbiTimeBarItem
e.Appointment.Data = 300 'Used for finding the classroom
With e.Appointment
newTimebar.Text = .Text
newTimebar.Start = .Start
newTimebar.End = .End
newTimebar.EntryID = System.Guid.NewGuid.ToString 'This is for tracking the timebar in other events
'Ordinarily this would be the database record ID
newTimebar.Tag = e.Index 'Add the appointment index to the tag so we can manipulate it in other events
End With
Dim curItem As New Dbi.WinControl.Schedule.dbiScheduleItem
curItem = FindItemInSched(e.Appointment.Data)
If Not (curItem Is Nothing) Then
curItem.TimeBars.Add(newTimebar)
e.Appointment.Cargo = newTimebar.EntryID ' Add the timebar ID to the cargo so we can manipulate it in other events
End If
Me.DbiSchedule1.Invalidate()
End Sub
Private Sub DbiDayView1_AfterAppointmentChange(ByVal sender As Object, ByVal e As Dbi.WinControl.DayView.AfterAppointmentChangeEventArgs) Handles DbiDayView1.AfterAppointmentChange
If Not (booleanTimeBarChanged) Then
Dim curSchedItem As Dbi.WinControl.Schedule.dbiScheduleItem
Dim curTimebar As Dbi.WinControl.Schedule.dbiTimeBarItem
Dim foundTimebar As New Dbi.WinControl.Schedule.dbiTimeBarItem
curSchedItem = FindItemInSched(e.Appointment.Data)
For Each curTimebar In curSchedItem.TimeBars
If curTimebar.EntryID = e.Appointment.Cargo Then
foundTimebar = curTimebar
Exit
For
End If
Next
foundTimebar.Start = e.Appointment.Start
foundTimebar.End = e.Appointment.End
foundTimebar.Text = e.Appointment.Text
foundTimebar.Tag = e.Index
Else
booleanTimeBarChanged = False
End If
Me.DbiDayView1.Refresh()
End Sub
Private Sub DbiSchedule1_AfterTimeBarMoved(ByVal sender As Object, ByVal e As Dbi.WinControl.Schedule.AfterTimeBarMovedEventArgs) Handles DbiSchedule1.AfterTimeBarMoved
Dim
curAppt As Dbi.WinControl.DayView.dbiDayAppointmentItem = Me.DbiDayView1.Appointments(e.TimeBarItem.Tag)
booleanTimeBarChanged = True
curAppt.Start = e.TimeBarItem.Start
curAppt.End = e.TimeBarItem.End
curAppt.Text = e.TimeBarItem.Text
booleanTimeBarChanged = False
Me.DbiDayView1.Invalidate()
End Sub
Private Sub DbiSchedule1_AfterTimeBarSized(ByVal sender As Object, ByVal e As Dbi.WinControl.Schedule.AfterTimeBarSizedEventArgs) Handles DbiSchedule1.AfterTimeBarSized
Dim curAppt As Dbi.WinControl.DayView.dbiDayAppointmentItem = Me.DbiDayView1.Appointments(e.TimeBarItem.Tag)
booleanTimeBarChanged = True
curAppt.Start = e.TimeBarItem.Start
curAppt.End = e.TimeBarItem.End
curAppt.Text = e.TimeBarItem.Text
booleanTimeBarChanged = False
Me.DbiDayView1.Invalidate()
End Sub
Private Sub DbiDayView1_AppointmentTextChange(ByVal sender As Object, ByVal e As Dbi.WinControl.DayView.AppointmentTextChangeEventArgs) Handles DbiDayView1.AppointmentTextChange
If Not (booleanTimeBarChanged) Then
Dim curSchedItem As Dbi.WinControl.Schedule.dbiScheduleItem
Dim curTimebar As Dbi.WinControl.Schedule.dbiTimeBarItem
Dim foundTimebar As New Dbi.WinControl.Schedule.dbiTimeBarItem
curSchedItem = FindItemInSched(Me.DbiDayView1.Appointments(e.Index).Data)
For Each curTimebar In
curSchedItem.TimeBars
If curTimebar.EntryID = Me.DbiDayView1.Appointments(e.Index).Cargo Then
foundTimebar = curTimebar
Exit For
End If
Next
foundTimebar.Start = Me.DbiDayView1.Appointments(e.Index).Start
foundTimebar.End = Me.DbiDayView1.Appointments(e.Index).End
foundTimebar.Text = Me.DbiDayView1.Appointments(e.Index).Text
foundTimebar.Tag = e.Index
Else
booleanTimeBarChanged = False
End If
Me.DbiDayView1.Refresh()
End Sub
Private Function FindItemInSched(ByVal intItemData As Integer) As Dbi.WinControl.Schedule.dbiScheduleItem
'Function to find a dbiScheduleItem based on it's Data property.
Dim findItem As Dbi.WinControl.Schedule.dbiScheduleItem
Dim foundItem As New Dbi.WinControl.Schedule.dbiScheduleItem
For Each findItem In Me.DbiSchedule1.Items
If findItem.Data = intItemData Then
foundItem = findItem
Exit For
End If
Next
Return foundItem
End Function
This is just the beginning of what you can accomplish with a handful of properties and events. You can add validation, data access, and custom dialogs to create a truly integrated application.
Take care and have a great day!
Back To The Top