Capture which resource is clicked on in timeline view

5 posts, 1 answers
  1. Karl
    Karl avatar
    172 posts
    Member since:
    Sep 2010

    Posted 25 Jul 2012 Link to this post

    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
  2. Answer
    Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 27 Jul 2012 Link to this post

    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 >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. John
    John avatar
    60 posts
    Member since:
    Nov 2006

    Posted 18 Sep 2013 Link to this post

    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!
  5. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 23 Sep 2013 Link to this post

    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 >>
  6. John
    John avatar
    60 posts
    Member since:
    Nov 2006

    Posted 23 Sep 2013 Link to this post

    Thanks that worked great
Back to Top
UI for WinForms is Visual Studio 2017 Ready