Hi,
I'm trying to load items from a database and display them on the resourceview of the calendar, but I cannot figure out how to do this exactly ???.
With following code I put appointments on the calendar (which is in resourceview):
private void calendar1_DateClick(object sender, ResourceDateEventArgs e)
{
if (e.Clicks == 2 && e.Button == MouseButtons.Left)
{
calendar1.ResetDrag();
Contact c = calendar1.GetContactAt(calendar1.PointToClient(MousePosition));
if (c == null)
return;
Appointment tpt = new Appointment();
tpt.StartTime = e.Date;
tpt.EndTime = e.Date + TimeSpan.FromDays(1);
tpt.HeaderText = "test";
tpt.Contacts.Add(c);
calendar1.Schedule.Items.Add(tpt);
}
}
Following code saves the appointment to the database (new record is correctly created in tables Item and ItemContacts):
private void cmdSave_Click(object sender, EventArgs e)
{
calendar1.SaveToDataSource(
reminderTableAdapter1,
styleTableAdapter1,
customBrushesTableAdapter1,
contactTableAdapter1,
locationTableAdapter1,
resourceTableAdapter1,
taskTableAdapter1,
itemTableAdapter1,
itemContactsTableAdapter1,
itemResourcesTableAdapter1,
recurrenceTableAdapter1,
recurrenceExceptionTableAdapter1,
recurrenceExceptionsTableAdapter1
);
}
I use the following code to load the data back to the calendar:
private void cmdLoad_Click(object sender, EventArgs e)
{
calendar1.Schedule.Clear();
plannerDataSet.Clear();
reminderTableAdapter1.Fill(plannerDataSet.Reminder);
styleTableAdapter1.Fill(plannerDataSet.Style);
customBrushesTableAdapter1.Fill(plannerDataSet.CustomBrushes);
contactTableAdapter1.Fill(plannerDataSet.Contact);
locationTableAdapter1.Fill(plannerDataSet.Location);
resourceTableAdapter1.Fill(plannerDataSet.Resource);
taskTableAdapter1.Fill(plannerDataSet.Task);
itemTableAdapter1.Fill(plannerDataSet.Item);
itemContactsTableAdapter1.Fill(plannerDataSet.ItemContacts);
itemResourcesTableAdapter1.Fill(plannerDataSet.ItemResources);
recurrenceTableAdapter1.Fill(plannerDataSet.Recurrence);
recurrenceExceptionTableAdapter1.Fill(plannerDataSet.RecurrenceException);
recurrenceExceptionsTableAdapter1.Fill(plannerDataSet.RecurrenceExceptions);
calendar1.LoadFromDataSource();
}
I get no error messages when executing this, but the calendar remains empty, no appointment is shown.
I've read tutorial #9 but I'm clueless why this won't work.
thanks for helping.