New to Telerik UI for WinForms? Download free 30-day trial

Determining Header Cell and its Resource ID in MouseDown Events in RadScheduler

Environment

Product Version Product Author
2024.2.514 UI for WinForms Dinko Krastev

Description

There could be a scenario where you want to get the header cell and its resource ID in the RadScheduler control when the user clicks on it. To achieve this, we can use the MouseDown event of the control. In the event handler, we can use the GetElementAtPoint() method of the ElementTree which will return the click element in the RadScheduler control. We can use this method to obtain other visual elements by a given location.

From the View object of the cell, we can call the GetResource() method to get the corresponding resource and its ID.

Solution

private void RadScheduler1_MouseDown(object sender, MouseEventArgs e)
{
    SchedulerHeaderCellElement schedulerHeaderCellElement = this.radScheduler1.ElementTree.GetElementAtPoint(e.Location) as SchedulerHeaderCellElement;
    if (schedulerHeaderCellElement != null)
    {
        if (e.Button == MouseButtons.Left)
        {
            var date = schedulerHeaderCellElement.Date;
            var resource = schedulerHeaderCellElement.View.GetResource();
            var resourceID = schedulerHeaderCellElement.View.GetResourceId();
        }
        else if (e.Button == MouseButtons.Right)
        {
            // Right-click logic can be added here
        }
        return;
    }
}

See Also

In this article