I have bound my appointments to a dataset and have specified a data member (table name). Everything is displaying properly. I need to get able to retrieve an appointment and I'm trying to use the GetAppointmentFromBindingListObject function. I am passing in a DataRowView that maps to one of the datarows in my bound dataset, but it never returns anything. Any help on what I could be doing wrong?
Hello Richard,
The reason GetAppointmentFromBindingListObject isn't working with DataTable is that you are passing the dataRow object instead of DataRowView object.
If you want to use DataTables, you should cast your DataRow to DataRowView. I made quick test using the code below:
DataTable dt = new DataTable();
dt.Columns.Add("A", typeof(Appointment));
dt.Rows.Add(new Appointment(DateTime.Now, DateTime.Now.AddDays(2)));
dt.Rows.Add(new Appointment(DateTime.Now, DateTime.Now.AddDays(5)));
ultraCalendarInfo1.DataBindingsForAppointments.DataSource = dt;
DataRow dr = dt.Rows[0];
DataRowView drv = dt.DefaultView[dt.Rows.IndexOf(dr)];
Appointment app = ultraCalendarInfo1.Appointments.GetAppointmentFromBindingListObject(drv) as Appointment;
MessageBox.Show(app.Subject);
Another possible approach could be with BindingList<T> rather than a DataSet/DataTable. For example:
BindingList <Appointment> list = new BindingList<Appointment>();
list.Add(new Appointment(DateTime.Now, DateTime.Now.AddDays(2)));
list.Add(new Appointment(DateTime.Now, DateTime.Now.AddDays(5)));
ultraCalendarInfo1.DataBindingsForAppointments.DataSource = list;
Appointment app = ultraCalendarInfo1.Appointments.GetAppointmentFromBindingListObject(list[1]) as Appointment;
Let me know if you have any questions.
Regards
I tried your approach and it still fails on the GetAppointmentFromBindingListObject. Here's my code after using your suggestion:
Dim strImageFilename As String = GetColString(dScheduleJobRow("Drawing_Filename"))
If strImageFilename.Trim <> String.Empty Then
If System.IO.File.Exists(strImageFilename) = True Then
Dim fs As System.IO.FileStream
fs = New System.IO.FileStream(strImageFilename, IO.FileMode.Open, IO.FileAccess.Read)
'get all the appointments for this job and set the image...
Dim dScheduleDetailRows() As DataRow = Me.dsDataEntryItem.Tables("Schedule_Detail").Select("Schedule_Job_ID = " & GetColInteger(dScheduleJobRow("Schedule_Job_ID")).ToString, String.Empty, DataViewRowState.CurrentRows)
If dScheduleDetailRows.Length > 0 Then
For Each dScheduleDetailRow As DataRow In dScheduleDetailRows
Dim drv As DataRowView = Me.dsDataEntryItem.Tables("Schedule_Detail").DefaultView(Me.dsDataEntryItem.Tables("Schedule_Detail").Rows.IndexOf(dScheduleDetailRow))
If Not IsNothing(drv) Then
Dim objAppointment As Appointment = DirectCast(Me.CalendarInfo1.Appointments.GetAppointmentFromBindingListObject(drv), Appointment)
If Not IsNothing(objAppointment) Then
objAppointment.Appearance.Image = System.Drawing.Image.FromStream(fs)
End If
Next
fs.Close()
fs = Nothing