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

Transferring back from destination listbox in code not working correctly

7 Answers 279 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Bex
Top achievements
Rank 1
Bex asked on 16 Mar 2012, 02:33 PM
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


7 Answers, 1 is accepted

Sort by
0
Bex
Top achievements
Rank 1
answered on 20 Mar 2012, 10:57 AM
Anyone? 
0
Peter Filipov
Telerik team
answered on 21 Mar 2012, 12:20 PM
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.
0
James
Top achievements
Rank 1
answered on 23 Jan 2013, 09:20 PM
Hi.

I was wondering what the answer to this is.  I am attempting to do the same thing and getting the same results.
0
Steve
Top achievements
Rank 1
answered on 24 Jan 2013, 08:51 AM
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
0
James
Top achievements
Rank 1
answered on 24 Jan 2013, 01:49 PM
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();

0
Peter Filipov
Telerik team
answered on 28 Jan 2013, 11:29 AM
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.
0
Terry Hoiness
Top achievements
Rank 1
answered on 01 Jul 2013, 07:49 PM
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;
}

Tags
ListBox
Asked by
Bex
Top achievements
Rank 1
Answers by
Bex
Top achievements
Rank 1
Peter Filipov
Telerik team
James
Top achievements
Rank 1
Steve
Top achievements
Rank 1
Terry Hoiness
Top achievements
Rank 1
Share this question
or