This is a migrated thread and some comments may be shown as answers.

SearchGrid Columns with Custom Appointment Class

1 Answer 100 Views
Scheduler and Reminder
This is a migrated thread and some comments may be shown as answers.
Yanick
Top achievements
Rank 1
Yanick asked on 28 Dec 2018, 11:55 PM

Hello everyone,

I am using the RadScheduler and RadSchedulerNavigator control with a Custom Appointment Class.

I would like to be able to add and remove columns to the default SearchGrid based on the fields that I added to my Custom Appointment Class.

I would also like that the search process handle this customs fields.

 

It is possible to edit SearchGrid Columns and handle custom fields in the search process? - How to do that?

 

I see SchedulerNavigatorElement.SearchGrid gives you access to the search grid. But I'm not able to Customize the search grid columns.

 

This is the documentation that i have used to customize appointment  (Just to be clear as much as possible about custom appointment class):

https://docs.telerik.com/devtools/winforms/controls/scheduler/data-binding/binding-to-custom-fields

 

Any help will be very appreciated.

 

Thank to all and have a holiday time!

1 Answer, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 31 Dec 2018, 09:13 AM
Hello, Yanick, 

The SearchGrid is populated with data by using data binding when you start typing in the search box. Hence, if you add programmatically any columns, they will be cleared when setting the DataSource property at a later moment internally by the search functionality. 

The possible solution that I can suggest is to handle the SchedulerNavigatorElement.SearchGrid.DataBindingComplete, add the custom field column and populate the respective grid cell programmatically.

public RadForm1()
{
    InitializeComponent();
 
    for (int i = 0; i < 10; i++)
    {
        AppointmentWithEmail a = new AppointmentWithEmail();
        a.Start = DateTime.Now;
        a.Duration = TimeSpan.FromHours(3);
        a.Summary = "A " + i;
        a.Email = "test" + i + "@telerik.com";
        this.radScheduler1.Appointments.Add(a);
    }
       
    this.radSchedulerNavigator1.SchedulerNavigatorElement.SearchGrid.DataBindingComplete += SearchGrid_DataBindingComplete;
}
 
private void SearchGrid_DataBindingComplete(object sender, GridViewBindingCompleteEventArgs e)
{
    if (!this.radSchedulerNavigator1.SchedulerNavigatorElement.SearchGrid.Columns.Contains("Email"))
    {
        this.radSchedulerNavigator1.SchedulerNavigatorElement.SearchGrid.Columns.Add("Email");
        foreach (GridViewRowInfo row in this.radSchedulerNavigator1.SchedulerNavigatorElement.SearchGrid.Rows)
        {
            AppointmentWrapper aw = row.DataBoundItem as AppointmentWrapper;
            if (aw != null)
            {
                FieldInfo appointmentInfo = typeof(AppointmentWrapper).GetField("appointment", BindingFlags.NonPublic | BindingFlags.Instance);
                AppointmentWithEmail a = appointmentInfo.GetValue(aw) as AppointmentWithEmail;
                row.Cells["Email"].Value = a.Email;
            }
        }
        this.radSchedulerNavigator1.SchedulerNavigatorElement.SearchGrid.MasterTemplate.Refresh();
    }
}
 
public class AppointmentWithEmail : Appointment
{
    public AppointmentWithEmail() : base()
    {
    }
 
    protected override Event CreateOccurrenceInstance()
    {
        return new AppointmentWithEmail();
    }
 
    private string email = string.Empty;
 
    public string Email
    {
        get
        {
            return this.email;
        }
        set
        {
            if (this.email != value)
            {
                this.email = value;
                this.OnPropertyChanged("Email");
            }
        }
    }
}

Note that this is just a sample solution and it may not cover all possible cases. Feel free to modify it in a way which suits your custom requirements best.

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Scheduler and Reminder
Asked by
Yanick
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or