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

RadListBox reordering event

14 Answers 208 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Chuck
Top achievements
Rank 1
Chuck asked on 22 Mar 2011, 04:56 PM
I am trying to use the drag-and-drop reordering capabilities of the list box control.  I see that there is an Index property in the EventArgs that seems to vary depending on where I drop the dragged list items.  I don't, however, understand the value of this property.  If I am moving items down in the list, Index seems to be the 0-based index of the item after which the dragged items have been dropped.  If I am moving items up in the list, the Index property seems to be 1 more than that.  Perhaps I am thinking of this incorrectly.  Could you please explain the expected behavior?  Thx.

14 Answers, 1 is accepted

Sort by
0
Peter Filipov
Telerik team
answered on 24 Mar 2011, 04:23 PM
Hi Chuck,

An event argument parameter contains the method get_offset(). It returns -1 when you are moving the item up and 1 when yo are moving item down.

Kind regards,
Peter Filipov
the Telerik team
0
Chuck
Top achievements
Rank 1
answered on 24 Mar 2011, 05:50 PM
The Offset field is set when one reorders items using the push buttons (up and down arrows) located next to the list.  When one uses the drag-and-drop method, the offset always appears to be 0 and the Index field seems to indicate the position in the list where the items are dropped.  My question is related to the drag-and-drop method of reordering.
0
Peter Filipov
Telerik team
answered on 28 Mar 2011, 04:23 PM
Hi Chuck,

If you are using the drag-and-drop functionality when the item is dropped the OnClientDropped client-event is fired. The get_dropPosition() property returns the relative position - either 0 (Above) or 1 (Below) toward the destination item. For more information please consult with the following help article.

Regards,
Peter Filipov
the Telerik team
0
Chuck
Top achievements
Rank 1
answered on 28 Mar 2011, 04:31 PM
Actually, my problem is with using the server-side Reordering event in an effort to keep my database in sync with the GUI.
0
Peter Filipov
Telerik team
answered on 31 Mar 2011, 08:34 AM
Hello Chuck,

RadListBox can perform transfer, delete and reorder operations and update the underlying data source control. Please check this demo overview for detailed information.

Greetings,
Peter Filipov
the Telerik team
0
Chuck
Top achievements
Rank 1
answered on 31 Mar 2011, 01:59 PM
Thx.  It's good to know that the control can do some of the database work for me.

However, I have not found a good explanation of the event args that are supplied to the Reordering event.  Is there somewhere an explanation of the properties, especially the Index property?
0
Peter Filipov
Telerik team
answered on 31 Mar 2011, 04:30 PM
Hello Chuck,

The Index property gets/sets the position of the item which is reordered.
For more information see this help article.

The Offset always returns 0 instead -1 or 1.
We are of this issue and we are going to fix it.

Best wishes,
Peter Filipov
the Telerik team
0
Chris
Top achievements
Rank 1
answered on 04 Jun 2013, 09:41 PM
Has the bug raised above ever been resolved?  I have Telerik 2012.2.912.35 and have just been trying to use the OnReordering event of the RadListBox so that when my list is re-ordered I can update the underlying database object but the e.Index is always 0 which means I can't tell if I have moved the item up or down in the list.

Please can anyone tell me if there is a way server side to identify the items which have been reordered so that I can update the database.  If not I guess I will have to resort to Infragistics again...
0
Peter Filipov
Telerik team
answered on 05 Jun 2013, 08:11 AM
Hello Chris,

The bug described in my previous post is resolved in Q3.2012. You could download that version or later release and test your project.

Regards,
Peter Filipov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Chris
Top achievements
Rank 1
answered on 05 Jun 2013, 08:17 AM
Unfortunately owing to a number of factors - including some issues with other controls - I do not have a current subscription and the last version I have is 2012.2.  Is it possible to get a patch or some update just for this one issue as I don't want to have to pay for another subscription especially for a bug which was already 18 months old when my subscription expired!
0
Peter Filipov
Telerik team
answered on 05 Jun 2013, 08:43 AM
Hi Chris,

I dig deeper and found out that the issue is fixed even in Q2.2012. I have tested the problem and everything is working fine with the mentioned version. In case that you have different issue please send me sample code to reproduce or record a video which demonstrates it.

Regards,
Peter Filipov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Chris
Top achievements
Rank 1
answered on 05 Jun 2013, 09:10 AM
Definately not fixed in the release I have which is listed as 2012.2.912.35.  My .aspx is 

<telerik:RadListBox ID="rlbStagesOnEvent" runat="server" AutoPostBack="true" 
AllowReorder="True" AutoPostBackOnReorder="True" DataTextField="EventStageName" DataValueField="ID" 
EmptyMessage="No Event Stages Defined" Height="100%" Width="100%"
OnSelectedIndexChanged="rlbStagesOnEvent_SelectedIndexChanged" OnReordering="rlbStagesOnEvent_Reordering" />

Note that I am loading an Object DataSource for the listbox.  Each EventStage object has an internal sequence number which is what I want to update in the database to reflect the change made.  My handler is 

protected void rlbStagesOnEvent_Reordering(object sender, RadListBoxReorderingEventArgs e)
{
RadListBoxItem liToMove = rlbStagesOnEvent.Items[rlbStagesOnEvent.SelectedIndex];
RadListBoxItem liOther = (e.Index == -1) ? rlbStagesOnEvent.Items[rlbStagesOnEvent.SelectedIndex - 1] : rlbStagesOnEvent.Items[rlbStagesOnEvent.SelectedIndex + 1];

// Read the event stage definition back from the database 
EventStage esToMove = new EventStage(int.Parse(liToMove.Value));
EventStage esOther = new EventStage(int.Parse(liOther.Value));

// Swap the sequence numbers over
int oldSequence = esToMove.Sequence;
esToMove.Sequence = esOther.Sequence;
esOther.Sequence = oldSequence;
esToMove.Update();
esOther.Update();
}

I have uploaded a video of the program running in debug as 

http://screencast.com/t/INxtXuma1m

If I can't get this to work can I add my own buttons and then re-order the items manually server side?  If not I will have to give up with the Telerik suite as nothing I have tried so far has worked for me...
0
Peter Filipov
Telerik team
answered on 05 Jun 2013, 09:51 AM
Hi Chris,

The offset issue is fixed. Regarding to the index of the reordering item you should use the following approach:
protected void Unnamed_Reordering(object sender, Telerik.Web.UI.RadListBoxReorderingEventArgs e)
{
    //e.Offset indicates whether the item is reorder up(-1) or down(1).
 
    //index of the reordering item
    var index = e.Items[0].Index;    
}
As soon as you tested the above code let me know if this resolves the case.

Regards,
Peter Filipov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Chris
Top achievements
Rank 1
answered on 05 Jun 2013, 10:08 AM
Thanks - you are quite correct it was my error - I was using index rather than offset in my code.
Tags
ListBox
Asked by
Chuck
Top achievements
Rank 1
Answers by
Peter Filipov
Telerik team
Chuck
Top achievements
Rank 1
Chris
Top achievements
Rank 1
Share this question
or