Transferring back from destination listbox in code not working correctly

8 posts, 0 answers
  1. Bex
    Bex avatar
    53 posts
    Member since:
    Jul 2011

    Posted 16 Mar 2012 Link to this post

    Hi

    I have two list boxes on my Page.
    When the page loads depending on the type of user, an item from the left listbox is transferred to the right listbox.
    The user can then transfer anything else from left to right.

    If an option is changed on the page, everything from the right needs to be transferred back to the left.

    I copied the example and have listboxes on my page like this:
    <telerik:RadListBox runat="server" ID="lstLeft" Height="200px" Width="200px" AllowTransfer="true" TransferToID="lstRight"/>
    <telerik:RadListBox runat="server" ID="lstRight" Height="200px" Width="200px" />

    Transferring initially from left to right woks fine using this:
    lstLeft.Transfer(listItem , lstLeft, lstRight);

    If I try it the other way round (to transfer back to the left) :
    lstRight.Transfer(listItem, lstRight, lstLeft);

    I get the following error:
    Specified argument was out of the range of valid values.
    Parameter name: sourceListBox 


    If I add AllowTransfer="true" TransferToID="lstLeft" to the right hand textbox the transfer works, but I get the transfer buttons to the right of the right list box as well as in between.

    What do I need to do to get this to work correctly?

    Bex


  2. Bex
    Bex avatar
    53 posts
    Member since:
    Jul 2011

    Posted 20 Mar 2012 Link to this post

    Anyone? 
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Peter Filipov
    Admin
    Peter Filipov avatar
    1028 posts

    Posted 21 Mar 2012 Link to this post

    Hi Bex,

    I've already answered your support ticket. To avoid duplication of the thread please let us continue our communication in a single thread.

    Regards,
    Peter Filipov
    the Telerik team
    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.
  5. James
    James avatar
    9 posts
    Member since:
    Jun 2012

    Posted 23 Jan 2013 Link to this post

    Hi.

    I was wondering what the answer to this is.  I am attempting to do the same thing and getting the same results.
  6. Steve
    Steve avatar
    3 posts
    Member since:
    Feb 2007

    Posted 24 Jan 2013 Link to this post

    Hi James

    I can't remember exactly what was happening but my post back from telerik says:
     If transfer is not allowed it is not possible to transfer items. To transfer items AllowTransfer and TransferToID properties should be set
    Does that make any sense or help at all?

    Bex
  7. James
    James avatar
    9 posts
    Member since:
    Jun 2012

    Posted 24 Jan 2013 Link to this post

    Hi Bex.

    Thanks for replying.  I Do have those properties set and still couldnt get it to work.  What I needed to do was to move values back from where the user selected them.  I got around this issue by cloning the item, addding it to the list box it originally belonged to and then clearing out the listbox that needed to be cleared.  Here is the code I used:

     

     

    RadListBoxItemCollection theList = radUserRecipientList.Items;

     

     

     

    foreach (RadListBoxItem theItem in theList)

     

    {

     

     

     

        RadListBoxItem itemToMove = theItem.Clone();

     

        radUserList.Items.Add(itemToMove);

    }

    radUserRecipientList.Items.Clear();

    radUserList.Sort =

     

    RadListBoxSort.Ascending;

     

    radUserList.SortItems();

  8. Peter Filipov
    Admin
    Peter Filipov avatar
    1028 posts

    Posted 28 Jan 2013 Link to this post

    Hello guys,

    I am sending you the sample project from the support ticket.

    Regards,
    Peter Filipov
    the Telerik team
    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.
  9. Terry Hoiness
    Terry Hoiness avatar
    1 posts
    Member since:
    Mar 2010

    Posted 01 Jul 2013 Link to this post

    I was trying to figure this out as well.  The following does the ground work for you - even if you're looking for something different, the idea's the same (you should be able to pick up the model of the two methods - it's simple).  

    1.  Catch the original transfer state
    2.  Set AllowTransfer to true
    3.  Set the transfer ID from source to destination
    4.  Perform the transfer.
    5.  Set AllowTransfer back to the original state.

    //Reset all selected back to source
         private void ResetList(RadListBox ListSource, RadListBox ListDestination)
         {
             bool allowTransfer = ListSource.AllowTransfer;
             ListSource.AllowTransfer = true;
             ListSource.TransferToID = ListDestination.ID;
             if (ListSource.Items.Count > 0)
    ListSource.Transfer(ListSource.Items, ListSource, ListDestination);
             ListSource.AllowTransfer = allowTransfer;
         }

    //Move items by value
    private void MoveListItems(RadListBox ListSource, RadListBox ListDestination, List<int?> values)
    {
        bool allowTransfer = ListSource.AllowTransfer;
        ListSource.AllowTransfer = true;
        ListSource.TransferToID = ListDestination.ID;
        foreach (int value in values)
             ListSource.Transfer(ListSource.FindItemByValue(value.ToString()), ListSource, ListDestination);
        ListSource.AllowTransfer = allowTransfer;
    }

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017