Question

I am using this sample code to get calendar appointments. I want to convert items to string : for example show the first item in a message box. What is the solution??

private void SearchAppointments_Click(object sender, RoutedEventArgs e)
    {
        Appointments appts = new Appointments();
        appts.SearchCompleted += new EventHandler<AppointmentsSearchEventArgs>(Appointments_SearchCompleted);
        appts.SearchAsync(DateTime.Now, DateTime.Now.AddDays(1), 2,null);
    }


    void Appointments_SearchCompleted(object sender, AppointmentsSearchEventArgs e)
    {
        try
        {
            //Bind the results to the list box that displays them in the UI.
            AppointmentResultsData.DataContext = e.Results;
        }
        catch (System.Exception)
        {
            //That's okay, no results.
        }
    }
Was it helpful?

Solution

The results are IEnumerable and you can do it for example like this:

  void Appointments_SearchCompleted(object sender, AppointmentsSearchEventArgs e)
  {
     try
     {
        AppointmentResultsData.DataContext = e.Results;
        MessageBox.Show(e.Results.ElementAt<Appointment>(0).Subject.ToString());
     }
     catch (System.Exception) { }
  }

Of course instead of a Subject you can show other properties of Appointment Class.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top