Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
4133
GetAppointmentFromBindingListObject
posted

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?

 

 

Parents
No Data
Reply
  • 53790
    posted

    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;

    MessageBox.Show(app.Subject);

    Let me know if you have any questions.

    Regards

Children