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

Capture which resource is clicked on in timeline view

4 Answers 85 Views
Scheduler and Reminder
This is a migrated thread and some comments may be shown as answers.
Karl
Top achievements
Rank 1
Karl asked on 25 Jul 2012, 09:10 AM
I have a scheduler control and want to know which resource header was clicked on when user click on a resource header cell.

Can someone please tell me how this is done?

Thanks.
Karl

4 Answers, 1 is accepted

Sort by
0
Accepted
Ivan Todorov
Telerik team
answered on 27 Jul 2012, 02:08 PM
Hi Karl,

Thank you for your question.

You can achieve this by handling the MouseClick event of RadScheduler and detecting which element was clicked. The following code snippet demonstrates this:
void radScheduler1_MouseClick(object sender, MouseEventArgs e)
{
    SchedulerResourcesHeaderElement resourceHeader = this.radScheduler1.RootElement.FindDescendant<SchedulerResourcesHeaderElement>();
    if (resourceHeader != null && resourceHeader.ControlBoundingRectangle.Contains(e.Location))
    {
        SchedulerCellElement clickedCell = this.radScheduler1.ElementTree.GetElementAtPoint(e.Location) as SchedulerCellElement;
        if (clickedCell != null)
        {
            foreach (Resource res in this.radScheduler1.Resources)
            {
                if (res.Name == clickedCell.Text)
                {
                    RadMessageBox.Show("You have clicked ResourceId: " + res.Id.KeyValue);
                    break;
                }
            }
        }
    }
}

I hope you find this useful. Feel free to ask if you have any additional questions.

Regards,
Ivan Todorov
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
0
John
Top achievements
Rank 1
answered on 18 Sep 2013, 04:57 PM
is there anyway to get the resource id from the  clickedCell object?

this
if (res.Name == clickedCell.Text)
                {

would only work if all the resources had different text.  I have multiple resources that have the same cell text so it's always just pulling the first one.

Thanks!
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 23 Sep 2013, 12:13 PM
Hello John,

Thank you for contacting Telerik Support.

You are able to modify the previous code snippet as follows:
private void radSchedulerControl_MouseClick(object sender, MouseEventArgs e)
{
    SchedulerResourcesHeaderElement resourceHeader = this.radSchedulerControl.RootElement.FindDescendant<SchedulerResourcesHeaderElement>();
    if (resourceHeader != null && resourceHeader.ControlBoundingRectangle.Contains(e.Location))
    {
        SchedulerCellElement clickedCell = this.radSchedulerControl.ElementTree.GetElementAtPoint(e.Location) as SchedulerCellElement;
 
        if (clickedCell != null)
        {
            GetResource();
        }
    }
}
 
public void GetResource()
{
    Point point = radSchedulerControl.PointToClient(Cursor.Position);
    SchedulerDayViewGroupedByResourceElement groupedDayViewElement = radSchedulerControl.SchedulerElement.ViewElement as SchedulerDayViewGroupedByResourceElement;
 
    if (groupedDayViewElement == null)
    {
        return;
    }
 
    foreach (SchedulerDayViewElement dayViewElement in groupedDayViewElement.GetDayViewElements())
    {
        int min = dayViewElement.ControlBoundingRectangle.X;
        int max = min + dayViewElement.ControlBoundingRectangle.Width;
        if (point.X >= min && point.X <= max)
        {
            EventId resource = dayViewElement.View.GetResources()[0].Id;
            MessageBox.Show(resource.KeyValue.ToString());
            return;
        }
    }
}

Please, have in mind that this code example is related to RadScheduler DayView.

I hope this information helps. Should you have further questions, I would be glad to help.

Regards,
Desislava
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
John
Top achievements
Rank 1
answered on 23 Sep 2013, 01:17 PM
Thanks that worked great
Tags
Scheduler and Reminder
Asked by
Karl
Top achievements
Rank 1
Answers by
Ivan Todorov
Telerik team
John
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or