Limiting ResourcesPerView for grouped TimelineView

2 Answers 41 Views
Scheduler and Reminder
Stephan
Top achievements
Rank 3
Bronze
Iron
Iron
Stephan asked on 11 Dec 2023, 04:42 PM

Hello,

I am using RadScheduler with a grouped TimelineView. The number of resources can be selected with a TrackBar, but if the selected value is to high, the view looks squezed and I got overlappings in my customized resource header elements. So my Idea is a minimum ResourceHeaderHeigth. I want to achieve this by calculating the maximum suitable ResourcesPerView value when the Trackbar is changed or the Form / Scheduler is resized. E.g. if my Scheduler has 250 px size, max 5 resources should be visible and if the size is resized to 200 px, only 4 should be shown, so that every resource has at least 50px height.

But to achieve this I need to get the size of the area, where the resources are paintet or SchedulerSize minus Header and Footer.

        private void tbVisibleResourceCount_ValueChanged(object sender, EventArgs e)
        {
            if (DesignMode)
                return;

            try
            {
                int val = (int) tbVisibleResourceCount.Value;

                if (val <= 0)
                {
                    tbVisibleResourceCount.Value = 1;
                }
                else
                {
                    var newValue = Math.Min(val, AppointmentsVm?.AktiveRessourcen?.Count ?? 0 /*rsTermine.Resources.Count*/);

                    /* todo
                    switch (rsTermine.SchedulerElement.ViewElement)
                    {
                        case SchedulerTimelineViewElement timelineElement:                           
                            break;
                    
                        case SchedulerDayViewElement dayViewElement:
                            break;

                        case SchedulerMonthViewElement monthViewElement:
                            break;

                        case TimelineGroupingByResourcesElement timelineGrouped:
                            IList<SchedulerTimelineViewElement> childTimelineElements = timelineGrouped.GetChildViewElements();
                            break;

                        case SchedulerDayViewGroupedByResourceElement dayViewGrouped:
                            break;

                        case SchedulerMonthViewGroupedByResourceElement monthViewGrouped:
                            break; 
                    }*/

                    rsTermine.ActiveView.ResourcesPerView = newValue;
                }

                SetAppointmentsMargin();
                _adjustBackgroundsTimer?.Reset();
            }
            catch (Exception ex)
            {
                LogHelper.HandleError<CalendarView>(this, $"Fehler in {nameof(tbVisibleResourceCount_ValueChanged)}", ex);
            }
        }

 

Hope you can help me with this problem.

 

Regards,

Stephan

2 Answers, 1 is accepted

Sort by
1
Accepted
Dinko | Tech Support Engineer
Telerik team
answered on 14 Dec 2023, 09:58 AM

Hi Stephan,

Thank you for the provided code snippet.

The SchedulerReosurcesHeaderElement holds only the resource header cells and the separator visual element. You could use its Size property for your calculations.

var view = this.radScheduler1.SchedulerElement.ViewElement;
if (view is TimelineGroupingByResourcesElement)
{
    TimelineGroupingByResourcesElement timelineGroupResourceElement = this.radScheduler1.ViewElement as TimelineGroupingByResourcesElement;
    var headerCell = timelineGroupResourceElement.ResourcesHeader.Size;
    var height = timelineGroupResourceElement.ResourcesHeader.Size.Height;
}

Give this a try and let me know if this is what you are looking for.

Regards,
Dinko | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
Stephan
Top achievements
Rank 3
Bronze
Iron
Iron
answered on 19 Dec 2023, 06:54 PM

Hello Dinko,

thanks for your help. Your answer solved my problem. I adjusted the event handler and call it additionally, when the scheduler is resized. This ensures that there is enough space for every shown resource.


private void tbVisibleResourceCount_ValueChanged(object sender, EventArgs e)
{
    if (DesignMode)
        return;

    try
    {
        int val = (int) tbVisibleResourceCount.Value;

        if (val <= 0)
        {
            tbVisibleResourceCount.Value = 1;
        }
        else
        {
            var newValue = Math.Min(val, AppointmentsVm?.AktiveRessourcen?.Count ?? 0);

            
            switch (rsTermine.SchedulerElement.ViewElement)
            {
                case SchedulerTimelineViewElement timelineElement:                           
                    break;
            
                case SchedulerDayViewElement dayViewElement:
                    break;

                case SchedulerMonthViewElement monthViewElement:
                    break;

                case TimelineGroupingByResourcesElement timelineGrouped:
                    //var headerCell = timelineGrouped.ResourcesHeader.Size;
                    var headerHeight = timelineGrouped.ResourcesHeader.Size.Height;
                    var maxResources = headerHeight / RESOURCE_MIN_HEIGHT; //120px
                    newValue = Math.Min(maxResources, newValue);
                    newValue = Math.Max(1, newValue);
                    break;

                case SchedulerDayViewGroupedByResourceElement dayViewGrouped:
                    break;

                case SchedulerMonthViewGroupedByResourceElement monthViewGrouped:
                    break; 
            }

            rsTermine.ActiveView.ResourcesPerView = newValue;
        }

        SetAppointmentsMargin();
        _adjustBackgroundsTimer?.Reset();
    }
    catch (Exception ex)
    {
        LogHelper.HandleError<CalendarView>(this, $"Fehler in {nameof(tbVisibleResourceCount_ValueChanged)}", ex);
    }
}

 

Regards

Stephan

Tags
Scheduler and Reminder
Asked by
Stephan
Top achievements
Rank 3
Bronze
Iron
Iron
Answers by
Dinko | Tech Support Engineer
Telerik team
Stephan
Top achievements
Rank 3
Bronze
Iron
Iron
Share this question
or