search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Move resource server side in Scheduler

Asked by Davide
4 months ago.

Hi,
I've a number of resources with some children for each one in alphabetical order.
When I add a child to a specific resource server side, this appears at bottom of the children's list of his parent resource. Only if I refresh all dataset the resource appears in the correct position.
Is there a method to use to decide (o move) the position programmatically without refresh?

Thank you
Davide

Answer posted by Dan Letecky [DayPilot]
4 months ago.

The resources will be displayed in the order specified in the Resources collection. When adding a new Resource just insert it at the specified position or sort the collection before updating the Scheduler.

Comment posted by Davide
4 months ago.

Ok but how can I decide the position of a specific children while creating?
This is my code:

me.dp.Resources.FindById("10-0-0").Children.Add(n)

where "n" is a new DayPilot.Web.Ui.Resource and the resource with id "10-0-0" has a lot of childrens into its collection.

There are no properties regarding on the position of an element during the adding operation. Neither as resource property.

Comment posted by Dan Letecky [DayPilot]
4 months ago.

The ResourceCollection class supports Insert() method that will let you insert a new Resource at the specified position.

You can do something like this (schematically):

        Resource nr = new Resource("Name", "ID");
        foreach (Resource resource in DayPilotScheduler1.Resources)
        {
            if (nr.Name.CompareTo(resource.Name) < 0)
            {
                int index = DayPilotScheduler1.Resources.IndexOf(resource);
                DayPilotScheduler1.Resources.Insert(index, nr);
            }
        }

Replace DayPilotScheduler1.Resources with the ResourceCollection instance that you are working with.

Comment posted by Davide
4 months ago.

Thank you for your code but the value of index variable is always equal to -1.
I tried with a lot of resources but the function me.dp.Resources.IndexOf(resource) is -1

This is another version of my code:
index = Me.dp.Resources.indexof(Me.dp.Resources.FindById("30-179-27933"))

This is an example of an existing resource. Infact the function Me.dp.Resources.FindById("30-179-27933") returns correctly a resource. But its IndexOf is always -1.

Where is my mistake?
Thanks

Comment posted by Davide
4 months ago.

ADDENDUM to previous post: the IndexOf property is greater then -1 but only for parents resources.
For children is always -1.
Unfortunately I've to place a child in a specific index position of it's parent children collection.
I hope this information could be useful for you to identify my mistake.

Thanks

Comment posted by Davide
4 months ago.

I've found a solution!!!!!

res = Me.dp.Resources.FindById("30-179-27933")
Dim index As Integer = Me.dp.Resources.FindById("30-0-0").Children.IndexOf(res)
Me.dp.Resources.FindById("30-0-0").Children.Insert(index - 1, n)

Working with children it works well!!!!

index = Me.dp.Resources.FindById("30-0-0").Children.IndexOf(res) where "res" is the last child of parent resource the value is greater then -1as required.
Now, using .Children.Insert(index - 1, n) the position is right!!!

Thank you for your effort

Davide

Comment posted by Dan Letecky [DayPilot]
4 months ago.

Great, thanks for posting the solution!

New Reply
This reply is
Your name (optional):