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

schedule resource color when databound

4 Answers 191 Views
Scheduler and Reminder
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 01 Mar 2013, 07:22 PM
I'm sure i messed this up somehow, but i can't figure out how at this point.

i had a schedule control with resources on it.  they were colored different colors.  it worked fine.

now i added databinding to add appointments to it.  bound to custom business objects.  now everything shows in a weird gray/black shade. see the example.  if i remove databinding it works fine again (of course there's no appointments).

I can't get the appointment summary to show either.  what am i doing wrong for that?  it's there if i double click and edit an appointment the summary/description are there, so i know binding is correct, but it won't show on the appointment itself.

here's my databinding code.  it's all done in code, nothing on the form itself.

			var appointmentMappingInfo = new AppointmentMappingInfo();
			appointmentMappingInfo.BackgroundId = "ApptStatus";
			appointmentMappingInfo.Description = "Description";
			appointmentMappingInfo.End = "EndDate";
			//appointmentMappingInfo.Location = "Location";
			//appointmentMappingInfo.MasterEventId = "ParentID";
			//appointmentMappingInfo.RecurrenceRule = "RecurrenceRule";
			appointmentMappingInfo.ResourceId = "ProviderId";
			//appointmentMappingInfo.Resources = "SchedulerAppointment";
			appointmentMappingInfo.Start = "StartDate";
			//appointmentMappingInfo.StatusId = "StatusID";
			appointmentMappingInfo.Summary = "Subject";
			schedulerBindingDataSource1.EventProvider.Mapping = appointmentMappingInfo;
 
 
			var resourceMappingInfo = new ResourceMappingInfo();
			resourceMappingInfo.Id = "Id";
			resourceMappingInfo.Name = "Name";
 
			schedulerBindingDataSource1.ResourceProvider.Mapping = resourceMappingInfo;
 
			_bsAppts = SchedulerRepository.GetAppointments();
 
			schedulerBindingDataSource1.ResourceProvider.DataSource = _opList;
			schedulerBindingDataSource1.EventProvider.DataSource = _bsAppts;
 
 
			schMain.DataSource = schedulerBindingDataSource1;

_opList is a binding list of your Resource object.
_bsAppts is a binding list of my business object appointments

Thanks!

EDIT to get the appintment summary to show, i had to handle the appointmentformatting event and change the forecolor of appointmentelement to black.  i still have the weird color problem above.

4 Answers, 1 is accepted

Sort by
0
Julian Benkov
Telerik team
answered on 06 Mar 2013, 02:36 PM
Hi John,

Despite my efforts, I was not able to replicate the case on my end using the reported scenario and code snippets. Please try to isolate the issue in a sample application including bound and unbound appointment processing with AppointmentFormatting event handler and send it to us with some part of your data to investigate it locally. This will allow me to provide you with adequate and helpful assistance.

Thank you for your time and cooperation. I am looking forward to your reply. 

Regards,
Julian Benkov
the Telerik team
WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
0
John
Top achievements
Rank 1
answered on 06 Mar 2013, 03:20 PM
i was able to reproduce it by just binding to a custom object.  
i can't attach a project to this but here's what i did.  I'm using 2013 q1

drop a scheduler on a form and call it schMain.

replace your form1 code with the code below.  it will reproduce the issue.
in the load event of the form, there's a method called BindForm.  if you comment out this line, it works.  the resources are all in color like they should be.  if you put the line back in, it breaks and they all go gray.  i attached screen shots of what i see too.

thanks!

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls.UI;
 
namespace telerikschedulerreproduce
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private List<Resource> _opList;
        private BindingList<SchedulerAppointment> _bsAppts;
 
        private void Form1_Load(object sender, EventArgs e)
        {
            var dayView = schMain.GetDayView();
 
            dayView.DayCount = 1;
 
            dayView.RulerScaleSize = 15;
 
            _opList = new List<Resource>();
 
            AddResources();
 
            foreach (var itm in _opList)
            {
                schMain.Resources.Add(itm);
            }
 
            schMain.GroupType = GroupType.Resource;
            dayView.ShowHeader = false;
            dayView.ShowAllDayArea = false;
            schMain.ActiveView.ResourcesPerView = 4;
 
            //comment this out and run it and it looks fine with colors.  put it back in and it's all gray
            BindForm();
        }
 
        private void BindForm()
        {
            var appointmentMappingInfo = new AppointmentMappingInfo();
            appointmentMappingInfo.End = "EndDate";
            appointmentMappingInfo.ResourceId = "ProviderId";
            appointmentMappingInfo.Start = "StartDate";
            appointmentMappingInfo.Summary = "Subject";
            schedulerBindingDataSource1.EventProvider.Mapping = appointmentMappingInfo;
 
 
            var resourceMappingInfo = new ResourceMappingInfo();
            resourceMappingInfo.Id = "Id";
            resourceMappingInfo.Name = "Name";
 
            schedulerBindingDataSource1.ResourceProvider.Mapping = resourceMappingInfo;
 
            _bsAppts = new BindingList<SchedulerAppointment>();// SchedulerRepository.GetAppointments();
 
            schedulerBindingDataSource1.ResourceProvider.DataSource = _opList;
            schedulerBindingDataSource1.EventProvider.DataSource = _bsAppts;
 
 
            AddDummyAppts();
 
            schMain.DataSource = schedulerBindingDataSource1;
        }
 
        private void AddDummyAppts()
        {
            var appt = new SchedulerAppointment();
            appt.UqId = Guid.NewGuid();
            appt.StartDate = DateTime.Now;
            appt.EndDate = DateTime.Now.AddMinutes(60);
            appt.Subject = "My Appt";
            appt.ProviderId = new EventId(1);
             
            _bsAppts.Add(appt);
        }
 
        private void AddResources()
        {
            var r1 = new Resource();
            var r2 = new Resource();
            var r3 = new Resource();
            var r4 = new Resource();
 
            r1.Color = Color.Red;
            r2.Color = Color.Blue;
            r3.Color = Color.Aqua;
            r4.Color = Color.Coral;
 
            r1.Id = new EventId(1);
            r2.Id = new EventId(2);
            r3.Id = new EventId(3);
            r4.Id = new EventId(4);
 
            r1.Name = "r1";
            r2.Name = "r2";
            r3.Name = "r3";
            r4.Name = "r4";
 
            _opList.Add(r1);
            _opList.Add(r2);
            _opList.Add(r3);
            _opList.Add(r4);
        }
    }
 
    public class SchedulerAppointment : INotifyPropertyChanged
    {
 
        private Guid _uqId;
        private DateTime _endDate;
        private DateTime _startDate;
        private string _subject;
 
        private EventId _resourceId;
         
        public EventId ProviderId
        {
            get { return _resourceId; }
            set
            {
                if (Equals(value, _resourceId)) return;
                _resourceId = value;
                OnPropertyChanged();
            }
        }
 
        public string Subject
        {
            get { return _subject; }
            set
            {
                if (value == _subject) return;
                _subject = value;
                OnPropertyChanged();
            }
        }
 
        public DateTime StartDate
        {
            get { return _startDate; }
            set
            {
                if (value.Equals(_startDate)) return;
                _startDate = value;
                OnPropertyChanged();
            }
        }
 
        public DateTime EndDate
        {
            get { return _endDate; }
            set
            {
                if (value.Equals(_endDate)) return;
                _endDate = value;
                OnPropertyChanged();
            }
        }
 
        public Guid UqId
        {
            get { return _uqId; }
            set
            {
                if (value.Equals(_uqId)) return;
                _uqId = value;
                OnPropertyChanged();
            }
        }
 
        public event PropertyChangedEventHandler PropertyChanged;
 
        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
0
John
Top achievements
Rank 1
answered on 06 Mar 2013, 03:29 PM
while playing with the reproduction project, i actually fixed the problem.  it shouldn't matter what order it's done in, so i think it's a bug but the work around is to bind the form before adding the resources.  it seems to work with limited testing so far.  My new load code is as follows:
note the bindform call is now above addresources.  that produces the attached screen shot which is what i wanted.

var dayView = schMain.GetDayView();
 
            dayView.DayCount = 1;
 
            dayView.RulerScaleSize = 15;
 
            _opList = new List<Resource>();
 
            BindForm();
 
            AddResources();
 
            foreach (var itm in _opList)
            {
                schMain.Resources.Add(itm);
            }
 
            schMain.GroupType = GroupType.Resource;
            dayView.ShowHeader = false;
            dayView.ShowAllDayArea = false;
            schMain.ActiveView.ResourcesPerView = 4;
0
Julian Benkov
Telerik team
answered on 08 Mar 2013, 03:27 PM
Hello John,

I logged the issue in our
Public Issue Tracking System. The fix will be available in one of the next our releases. Currently, you can continue using your solution to work properly in this scenario.

Thank for the detailed description and code snippets. Your Telerik points have been updated.

Greetings,
Julian Benkov
the Telerik team
WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
Tags
Scheduler and Reminder
Asked by
John
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
John
Top achievements
Rank 1
Share this question
or