Programmerare, skeptiker, sekulärhumanist, antirasist.
Författare till bok om C64 och senbliven lantis.
Röstar pirat.
2008-12-13
This is a really mighty control that mimics the day view in the Outlook calendar. To use the control, add it to your toolbox and then drag the control (named DayView) to a form.
It has lots of properties you can use to adjust the behaviour and appearance that you can experiment with. I want to show how to add bookings to the control.
First, you must know what bookings you want to add. In a real application, that information might be loaded from a database into a variable that is declared as a member to the form. In my example, I hard code a couple of bookings.
First, I need an entity that represent a booking. This probably has more fields in a real application (like the primary key of the booking in the database).
Public Class Booking
Public BookingStart As DateTime
Public BookingEnd As DateTime
Public Sub New(ByVal BookingStart As DateTime, ByVal BookingEnd As DateTime)
Me.BookingStart = BookingStart
Me.BookingEnd = BookingEnd
End Sub
End Class
Then, I declare a list of bookings as a member of my form.
Private mBookings As List(Of Booking)
And in the load event of my form, I pretend to load bookings from the database by hard coding a couple of them.
mBookings = New List(Of Booking)()
mBookings.Add(New Booking(New DateTime(2008, 5, 15, 10, 0, 0), New DateTime(2008, 5, 15, 12, 0, 0)))
mBookings.Add(New Booking(New DateTime(2008, 5, 15, 16, 0, 0), New DateTime(2008, 5, 15, 17, 30, 0)))
Also, set the desired start date to the DayView control.
DayView1.StartDate = New DateTime(2008, 5, 15)
Finally, the control will raise the ResolveAppointments event when it wants to know about your bookings. Respond to that by iterating through your loaded bookings, and tell the control about what you want it to show.
Private Sub DayView1_ResolveAppointments(ByVal sender As Object, ByVal args As Calendar.ResolveAppointmentsEventArgs) Handles DayView1.ResolveAppointments
For Each B As Booking In mBookings
Dim A As New Calendar.Appointment()
A.StartDate = B.BookingStart
A.EndDate = B.BookingEnd
args.Appointments.Add(A)
Next
End Sub
There are other events that you could handle, if you want to keep track of what the user is doing with the control.
Categories: Microsoft .NET
Bjud mig på en kopp kaffe (20:-) som tack för bra innehåll!
Hi Anders Hesselbom,
Article is very good. I was able to implement in vb.net. But the same thing i want to implement in asp.net. Please let me know how i could achieve it.
Hello everyone,
I am making an application in vb.net 2010 and using dayview control for appointments. I want to link dayview control to my backend database i.e. in ms access 2007. What i need is when ever some one takes an appointment on phone or in person and when i add some info on the dayview control it gets store in the table in the backend. Please help I am badly stuck in this.
I have used day view control in my project but i am serious trouble saving the appointment and fetching it, can u please gimme a format or proper way to do that. ASAP