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

How to get current resource from radscheduler?

16 Answers 626 Views
Scheduler and Reminder
This is a migrated thread and some comments may be shown as answers.
Kian
Top achievements
Rank 1
Kian asked on 23 Sep 2010, 09:25 PM
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

16 Answers, 1 is accepted

Sort by
0
Kian
Top achievements
Rank 1
answered on 25 Sep 2010, 06:38 PM
Hi telerik admin,

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

Thanks.

0
Kian
Top achievements
Rank 1
answered on 26 Sep 2010, 12:01 PM
Just god knows where are u
0
Dobry Zranchev
Telerik team
answered on 27 Sep 2010, 01:36 PM
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
0
Kian
Top achievements
Rank 1
answered on 27 Sep 2010, 04:04 PM
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
0
Kian
Top achievements
Rank 1
answered on 28 Sep 2010, 08:36 AM
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
0
Dobry Zranchev
Telerik team
answered on 01 Oct 2010, 01:09 PM
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
0
Kian
Top achievements
Rank 1
answered on 03 Oct 2010, 01:00 PM

Thank you.
0
Karl
Top achievements
Rank 1
answered on 18 Jun 2012, 09:31 AM
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();

0
Karl
Top achievements
Rank 1
answered on 18 Jun 2012, 02:53 PM
Nevermind my previous post. I worked out the correct code, and put it in the correct event and it works.
0
Aaron
Top achievements
Rank 1
answered on 28 Feb 2013, 09:08 PM
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.
0
Jack
Telerik team
answered on 05 Mar 2013, 02:03 PM
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.
0
Emad
Top achievements
Rank 1
answered on 03 Dec 2015, 06:44 PM
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
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 04 Dec 2015, 12:57 PM
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
0
Emad
Top achievements
Rank 1
answered on 04 Dec 2015, 04:41 PM

Hi Dess,

 

Thank you for , please refer to below demo.

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

I want when click to create appointment to resource id in form created event.

advice.

Thanks.

Emad

0
Emad
Top achievements
Rank 1
answered on 04 Dec 2015, 05:25 PM

Solved by below code

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

 

Thanks

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 08 Dec 2015, 12:40 PM
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
Tags
Scheduler and Reminder
Asked by
Kian
Top achievements
Rank 1
Answers by
Kian
Top achievements
Rank 1
Dobry Zranchev
Telerik team
Karl
Top achievements
Rank 1
Aaron
Top achievements
Rank 1
Jack
Telerik team
Emad
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or