How to get current resource from radscheduler?

17 posts, 0 answers
  1. Kian
    Kian avatar
    15 posts
    Member since:
    Sep 2010

    Posted 23 Sep 2010 Link to this post

    Hi Admin,

    I want to know about how to get resource related to the current cell of radscheduler.
    I want to pass the ID of selected resource to my custom New/Edit Appointment Form to fill the resource combo box.

    I am looking forward to hearing from you as soon as possible.

    Thank you in advance.

    best regard.

    Kian
  2. Kian
    Kian avatar
    15 posts
    Member since:
    Sep 2010

    Posted 25 Sep 2010 Link to this post

    Hi telerik admin,

    I still I have a problem with RadScheduler to get selected resource.
    Please help me.

    Thanks.

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Kian
    Kian avatar
    15 posts
    Member since:
    Sep 2010

    Posted 26 Sep 2010 Link to this post

    Just god knows where are u
  5. Dobry Zranchev
    Admin
    Dobry Zranchev avatar
    348 posts

    Posted 27 Sep 2010 Link to this post

    Hi Kian,

    Thank you for writing.
     
    If I understand correctly, you want to take a resource from the view. However, I cannot understand whether you are using RadScheduler in grouping mode or not. Please provide me with additional details on this matter.

    Commonly, if you click on a cell, you could take this cell by using the GetCellAtPointment method of the SchedulerUIHelper class. After that you could take the ViewElement from the hierarchy of the parents. Finally, you should call the GetResources method from the ViewElement.View.

    In regards to the response time in our forums, please refer to the following articles:
    Important Information on Using the Telerik Forums
    Support Options

    I am looking forward to your response.

    Sincerely yours,
    Dobry Zranchev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Kian
    Kian avatar
    15 posts
    Member since:
    Sep 2010

    Posted 27 Sep 2010 Link to this post

    Dear Admin,

    Firs of all thank you for your help.

    Yes, I use RadScheduler in grouping mode. I have a table named Employee, then I create resources for each employee in my RadScheduler. (I use RadScheduler in DayView mode)
    Also, I create my  appointment form instead of AppointmentEditDialog of RadScheduler.
    In my appointment form, I have a label that I want to show selected employee name. So, I need to pass the ID of employee from RadScheduler Form to my appintment form to retrive employee name by ID to fill the label.

    So, I need to get current resource ID that was selected by user in RadScheduler

    I have not tried your solution yet. I hope it will work.

    Thank you again.
    Regards.
    Kian
  7. Kian
    Kian avatar
    15 posts
    Member since:
    Sep 2010

    Posted 28 Sep 2010 Link to this post

    Dear Admin,

    Thank you for your solution. It worked.
    I wrote this code to get current resource. Does it correct?

     Dim cells As List(Of SchedulerCellElement) = SchedulerUIHelper.GetSelectedCells(RadScheduler1)
     EmployeeID = cells(0).View.GetResources()(0).Id.KeyValue

    Best regards.

    Kian
  8. Dobry Zranchev
    Admin
    Dobry Zranchev avatar
    348 posts

    Posted 01 Oct 2010 Link to this post

    Hi Kian,

    Thank you for writing back.
     
    In order to take the resource in day view grouping mode you could you use the following code snippet.
     
    Point point = this.radScheduler1.PointToClient(Cursor.Position);
    SchedulerDayViewGroupedByResourceElement groupedDayViewElement = this.radScheduler1.SchedulerElement.ViewElement as SchedulerDayViewGroupedByResourceElement;
    SchedulerCellElement cellElement = SchedulerUIHelper.GetCellAtPoint(point, groupedDayViewElement.GetDayViewElements());
    SchedulerDayViewElement dayViewElement = cellElement.Parent.Parent.Parent.Parent.Parent.Parent as SchedulerDayViewElement;
    dayViewElement.View.GetResources()[0];
     
    In grouping mode each view has only one resource.

    You solution is also correct but it will work only if you have a selected cell.

    If you have other question, feel free to write.

    Greetings,
    Dobry Zranchev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  9. Kian
    Kian avatar
    15 posts
    Member since:
    Sep 2010

    Posted 03 Oct 2010 Link to this post


    Thank you.
  10. Karl
    Karl avatar
    172 posts
    Member since:
    Sep 2010

    Posted 18 Jun 2012 Link to this post

    Is there a way to do this in timeline view? When a user clicks in any cell (either on an appointment or in an empty cell) I need to get data about the resource.

    I have tried modifying the code posted here, but CellElement is always null.

    As soon as I have a value in timelineElement, I see a property called CurrentResourceIndex, but no matter which row I click in, this is always 0
    Point point = Schedule.PointToClient(Cursor.Position);
    TimelineGroupingByResourcesElement timelineElement = Schedule.SchedulerElement.ViewElement as TimelineGroupingByResourcesElement;
    SchedulerCellElement cellElement = SchedulerUIHelper.GetCellAtPoint(point, timelineElement.GetTimelineElements());
    SchedulerDayViewElement dayViewElement = cellElement.Parent.Parent.Parent.Parent.Parent.Parent as SchedulerDayViewElement;
    SchedulerResourceCollection resources = dayViewElement.View.GetResources();

  11. Karl
    Karl avatar
    172 posts
    Member since:
    Sep 2010

    Posted 18 Jun 2012 Link to this post

    Nevermind my previous post. I worked out the correct code, and put it in the correct event and it works.
  12. Aaron
    Aaron avatar
    12 posts
    Member since:
    Mar 2012

    Posted 28 Feb 2013 Link to this post

    Is there a method for getting the resource regardless of the current view? Having to dig through different object layers depending on the view to find the resource ID is very cumbersome. I would need to implement 3-4 different code patterns to find the resource depending on the view.
  13. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 05 Mar 2013 Link to this post

    Hello Aaron,

    It depends on your starting point. For example, when you have the Appointment object, you can access its ResourceId property. When you have a SchedulerCellElement, you can find the ancestor SchedulerViewVisualElement. Its View property contains the GetResources method that will return the current resource. Here is a sample:
    SchedulerCellElement cell = e.CellElement;
    SchedulerViewVisualElement dayViewElement = cell.FindAncestor<SchedulerViewVisualElement>();
    SchedulerResourceCollection resources = dayViewElement.View.GetResources();

    I hope it helps.
     
    All the best,
    Jack
    the Telerik team
    WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Join us for a FREE webinar to see all the new stuff in action.

    Interested, but can’t attend? Register anyway and we’ll send you the recording.
  14. Emad
    Emad avatar
    16 posts
    Member since:
    Dec 2015

    Posted 03 Dec 2015 Link to this post

    Hi,
     I have radscheduler in group mode, I want to get resource id on form created event to assign the same to combobox in advanced form.
    I do insert manually

    Thanks,
    Emad
  15. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 04 Dec 2015 Link to this post

    Hello Emad,

    Thank you for writing.

    Please refer to the following code snippet demonstrating how to get the resources id for the current view:
    public Form1()
    {
        InitializeComponent();
     
        //populate with resources
        GroupByResources();
    }
     
    private void GroupByResources()
    {
        Color[] colors = new Color[]
        {
            Color.LightBlue, Color.LightGreen, Color.LightYellow,
            Color.Red, Color.Orange, Color.Pink, Color.Purple, Color.Peru, Color.PowderBlue
        };
     
        string[] names = new string[]
        {
            "Alan Smith", "Anne Dodsworth",
            "Boyan Mastoni", "Richard Duncan", "Maria Shnaider"
        };
     
        for (int i = 0; i < names.Length; i++)
        {
            Resource resource = new Resource();
            resource.Id = new EventId(i);
            resource.Name = names[i];
            resource.Color = colors[i];
            this.radScheduler1.Resources.Add(resource);
        }
     
        this.radScheduler1.GroupType = GroupType.Resource;
    }
     
    private void radButton1_Click(object sender, EventArgs e)
    {
        //get resources id for the current view
        SchedulerDayViewGroupedByResourceElement dayView = this.radScheduler1.ViewElement as SchedulerDayViewGroupedByResourceElement;
        foreach (RadElement el in dayView.Children)
        {
            SchedulerDayViewElement d = el as SchedulerDayViewElement;
            if (d != null)
            {
                SchedulerResourceCollection resources = d.View.GetResources();
                foreach (Resource r in resources)
                {
                    Console.WriteLine(r.Id);
                }
            }
        }
    }

    I hope this information helps. Should you have further questions I would be glad to help.
     
    Regards,
    Dess
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  16. Emad
    Emad avatar
    16 posts
    Member since:
    Dec 2015

    Posted 04 Dec 2015 in reply to Dess Link to this post

    Hi Dess,

     

    Thank you for reply, please refer to below demo.

    http://demos.telerik.com/aspnet-ajax/scheduler/examples/resourcegrouping/defaultcs.aspx

    I want when user double click to create new appointment to ger resource id in form created event.

    Please advice.

    Thanks.

    Emad

  17. Emad
    Emad avatar
    16 posts
    Member since:
    Dec 2015

    Posted 04 Dec 2015 in reply to Emad Link to this post

    Solved by below code

    String xx = e.Appointment.Resources.GetResourceByType("USERNAME").Key.ToString();

     

    Thanks

  18. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 08 Dec 2015 Link to this post

    Hello Emad,

    Thank you for writing.

    I am glad that you have found a suitable solution for your case. Indeed, the Appointment.Resources property gives you access to the associated resource.

    I hope this information helps. Should you have further questions I would be glad to help.
     
    Regards,
    Dess
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for WinForms is Visual Studio 2017 Ready