0
votes

I am using DevExpress 16, am scheduling appointment dynamically using database data. Now, I scheduled my appointment successfully. I need to change appointment label background color programmatically.

I found some coding to change appointment label background color, like this,

Dim labels As AppointmentLabelCollection = schedulerControl1.Storage.AppointmentStorage.Labels
For i As Integer = 0 To labels.Count - 1
    Dim currentLabel As AppointmentLabel = labels(i)
    If currentLabel.Color = someColor Then
        newApt.LabelId = i
        Exit For
    End If
Next

But, I'm unable to use this code to set the background color, it shows me an error as below:

Code error

I believe this above error due to AppointmentStorage disabled during design time (in Properties window of the Scheduler control) itself. Refer the below image:

See properties, that appointment->Storage->SchedulerStorage1

Any help will be appreciated.

1
Your title states that you want to know how to make the change programmatically but you already know how to do that. You just posted how to do that. Your question seems to suggest that what you actually want is to make the change via the designer. Is that the case? Please edit your question or title so that they are not contradictory.jmcilhinney
The code sample you supplied seems to be searching through all the labels and when it finds a label matching a certain color, it changes the labelID (which by the way seems to be marked as obsolete these days) of the appointment empty appointment you defined in your code above. Sadly the code makes no sense to me. Surely you should be changing the .Color property. Whether something is disabled at design time or not, shouldn't affect code that you're writing at all.David Wilson

1 Answers

0
votes

Go through documentation: Appointment Labels and Statuses

Labels are stored in the AppointmentStorage.Labels collection. An individual label is represented by the AppointmentLabel object. To access a label's display name and color use its UserInterfaceObject.DisplayName and AppointmentLabel.Color properties.

Instead of using labels for appointments, you can paint the appointment's background in the SchedulerControl.CustomDrawAppointmentBackground event handler. This is the another approach which can be used customize skin appearance. You can use another custom drawing events also..

Example from documentation:

public static void scheduler_CustomDrawAppointmentBackground(object sender, CustomDrawObjectEventArgs e)
{
    AppointmentViewInfo viewInfo = e.ObjectInfo as AppointmentViewInfo;
    // Specify the ratio of a completed task to the entire task.
    double completenessRatio = 0.25 * ((int)(viewInfo.Appointment.ResourceId) % 4);
    // Draw an appointment as usual.
    e.DrawDefault();
    // Draw a background rectangle.
    Rectangle bounds = CalculateEntireAppointmentBounds(viewInfo);
    DrawBackGroundCore(e.Cache, bounds, completenessRatio);
    // Indicate that no default drawing is required.
    e.Handled = true;
}