Hi,
I'm trying to insert items to destination listbox to desired index. If any item is selected in the destination lisbox then the transfered items should be inserted above the selected item. I'm using allowtransfer property for transferring the items.
In transferring event i used "e.Cancel" to cancel the regular transfer when there is any item selected in the destination listbox.
e.Cancel = True
For Each item As RadListBoxItem In e.Items
e.DestinationListBox.Items.Insert(e.DestinationListBox.SelectedIndex, item)
Next
Insert doesn't work. What am I doing wrong? It doesn't give any error but doesn't work either. I have other functionality for which I have to make this happen through code behind itself.
Thanks,
Arjun
I'm trying to insert items to destination listbox to desired index. If any item is selected in the destination lisbox then the transfered items should be inserted above the selected item. I'm using allowtransfer property for transferring the items.
In transferring event i used "e.Cancel" to cancel the regular transfer when there is any item selected in the destination listbox.
e.Cancel = True
For Each item As RadListBoxItem In e.Items
e.DestinationListBox.Items.Insert(e.DestinationListBox.SelectedIndex, item)
Next
Insert doesn't work. What am I doing wrong? It doesn't give any error but doesn't work either. I have other functionality for which I have to make this happen through code behind itself.
Thanks,
Arjun
5 Answers, 1 is accepted
0
Shinu
Top achievements
Rank 2
answered on 15 Jul 2014, 07:56 AM
Hi ARJUN,
Please have a look into the sample code snippet which works fine at my end. Please provide your full code if it doesn't help.
ASPX:
VB:
Thanks,
Shinu.
Please have a look into the sample code snippet which works fine at my end. Please provide your full code if it doesn't help.
ASPX:
<
telerik:RadListBox
ID
=
"rlstboxSourceList"
runat
=
"server"
AutoPostBackOnTransfer
=
"true"
SelectionMode
=
"Multiple"
AllowTransfer
=
"true"
TransferToID
=
"rlstboxDestinationList"
OnTransferring
=
"rlstboxSourceList_Transferring1"
>
<
Items
>
<
telerik:RadListBoxItem
Text
=
"Item1"
/>
<
telerik:RadListBoxItem
Text
=
"Item2"
/>
<
telerik:RadListBoxItem
Text
=
"Item3"
/>
<
telerik:RadListBoxItem
Text
=
"Item4"
/>
<
telerik:RadListBoxItem
Text
=
"Item5"
/>
<
telerik:RadListBoxItem
Text
=
"Item6"
/>
</
Items
>
</
telerik:RadListBox
>
<
telerik:RadListBox
ID
=
"rlstboxDestinationList"
runat
=
"server"
SelectionMode
=
"Multiple"
>
<
Items
>
<
telerik:RadListBoxItem
Text
=
"Item7"
/>
<
telerik:RadListBoxItem
Text
=
"Item8"
/>
</
Items
>
</
telerik:RadListBox
>
VB:
Protected
Sub
rlstboxSourceList_Transferring1(sender
As
Object
, e
As
Telerik.Web.UI.RadListBoxTransferringEventArgs)
Dim
index
As
Integer
For
Each
item
As
RadListBoxItem
In
e.Items
index = e.DestinationListBox.SelectedIndex
rlstboxDestinationList.Items.Insert(index, item)
Next
End
Sub
Thanks,
Shinu.
0
ARJUN
Top achievements
Rank 1
answered on 15 Jul 2014, 06:54 PM
Hi Shinu,
Thanks for your response. The code which you posted works fine but that's the exact same thing what i have at my side too. I think I'm missing something. Below is my code.
<telerik:RadListBox ID="RadListBox_Left" Height="300px" Width="300px" runat="server"
AllowTransfer="true" TransferMode="Move" TransferToID="RadListBox_Right" Sort="Ascending"
SelectionMode="Multiple" AllowTransferOnDoubleClick="false" AutoPostBackOnTransfer="true" >
</telerik:RadListBox>
<telerik:RadListBox ID="RadListBox_Right" Height="300px" Width="300px" runat="server"
AllowReorder="true">
</telerik:RadListBox>
Protected Sub RadListBox_Left_Transferring(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadListBoxTransferringEventArgs) Handles RadListBox_Left.Transferring
If e.DestinationListBox.ID = "RadListBox_Right" Then
If e.DestinationListBox.SelectedIndex > -1 Then
For Each item As RadListBoxItem In e.Items
RadListBox_Right.Items.Insert(e.DestinationListBox.SelectedIndex, item)
Next
End If
End If
End Sub
Thanks,
Arjun
Thanks for your response. The code which you posted works fine but that's the exact same thing what i have at my side too. I think I'm missing something. Below is my code.
<telerik:RadListBox ID="RadListBox_Left" Height="300px" Width="300px" runat="server"
AllowTransfer="true" TransferMode="Move" TransferToID="RadListBox_Right" Sort="Ascending"
SelectionMode="Multiple" AllowTransferOnDoubleClick="false" AutoPostBackOnTransfer="true" >
</telerik:RadListBox>
<telerik:RadListBox ID="RadListBox_Right" Height="300px" Width="300px" runat="server"
AllowReorder="true">
</telerik:RadListBox>
Protected Sub RadListBox_Left_Transferring(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadListBoxTransferringEventArgs) Handles RadListBox_Left.Transferring
If e.DestinationListBox.ID = "RadListBox_Right" Then
If e.DestinationListBox.SelectedIndex > -1 Then
For Each item As RadListBoxItem In e.Items
RadListBox_Right.Items.Insert(e.DestinationListBox.SelectedIndex, item)
Next
End If
End If
End Sub
Thanks,
Arjun
0
Shinu
Top achievements
Rank 2
answered on 16 Jul 2014, 03:56 AM
Hi ARJUN,
From your code I have noticed you are not setting SelectionMode as Multiple for the Source RadListBox. Please do the following modification in your code which works fine at my end.
ASPX:
Thanks,
Shinu.
From your code I have noticed you are not setting SelectionMode as Multiple for the Source RadListBox. Please do the following modification in your code which works fine at my end.
ASPX:
<
telerik:RadListBox
ID
=
"rlstboxDestinationList"
runat
=
"server"
AllowReorder
=
"true"
SelectionMode
=
"Multiple"
>
</
telerik:RadListBox
>
Thanks,
Shinu.
0
ARJUN
Top achievements
Rank 1
answered on 16 Jul 2014, 01:35 PM
Hi Shinu,
Thanks. That works fine now.
Is there a way to get this working without the multiple selection for destination.....???? I cannot use multiple selection in destination listbox due to my application scenario. Not using multiple selection is a major thing for my application.
Can you suggest work around for this.
Thanks,
Arjun
Thanks. That works fine now.
Is there a way to get this working without the multiple selection for destination.....???? I cannot use multiple selection in destination listbox due to my application scenario. Not using multiple selection is a major thing for my application.
Can you suggest work around for this.
Thanks,
Arjun
0
ARJUN
Top achievements
Rank 1
answered on 16 Jul 2014, 01:53 PM
Shinu,
It's the multiple selection which is not letting the insert work.
For Each item As RadListBoxItem In e.Items
RadListBox_Right.Items.Insert(index, item)
RadListBox_Right.Items(index).Selected = False
Next
The above code lets any number of items to be inserted to destination.
This solves my issue.
Thanks,
Arjun
It's the multiple selection which is not letting the insert work.
For Each item As RadListBoxItem In e.Items
RadListBox_Right.Items.Insert(index, item)
RadListBox_Right.Items(index).Selected = False
Next
The above code lets any number of items to be inserted to destination.
This solves my issue.
Thanks,
Arjun