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

Adding Items to RadListBox

2 Answers 319 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Doug Arneson
Top achievements
Rank 1
Doug Arneson asked on 25 Sep 2009, 08:01 PM

Hello,

 

I have three RadListBoxes on a page. First one is populated by a SQLDataSource. When an item is clicked on the first RadListBox, I want the item to add to the other two listboxes.  The problem is that only one RadlistBox will populate with the selected item depending on which list box is last in the procedure.

I’m using VS 2008, and RadControls version: 2009.2.826.35

 

Sample ASP:


<telerik:RadListBox ID="RadListBox1" runat="server" DataSourceID="dsEDBRecords" AllowDelete="true"  Style="text-align: left;" AutoPostBack="true" DataTextField="FIELDNAME" DataValueField="UVALUE" Height="150px" Width="200px" OnSelectedIndexChanged="SetValue1" SelectionMode="Single"  > </telerik:RadListBox> 
 
<telerik:RadListBox ID="RadListBox2"  runat="server" AllowDelete="false" Style="text-align: left;"  AutoPostBack="true" Height="150px" Width="200px"></telerik:RadListBox> 
 
<telerik:RadListBox ID="RadListBox3" runat="server" AllowDelete="false" Style="text-align: left;" AutoPostBack="true" Height="150px" Width="200px" ></telerik:RadListBox> 
 

CODE BEHIND:
Protected Sub SetValue1(ByVal sender As Object, ByVal e As System.EventArgs)  
        Dim lbListBox As RadListBox = sender 
        Dim strItem As RadListBoxItem = lbListBox.SelectedItem  
        Dim strItem1 As RadListBoxItem = lbListBox.SelectedItem  
 
        RadListBox3.Items.Add(strItem)  
        RadListBox3.ClearSelection()  
        RadListBox2.Items.Add(strItem1)  
        RadListBox2.ClearSelection()  
End Sub  
 

Thanks in advance for all assistance.

Doug

2 Answers, 1 is accepted

Sort by
0
Accepted
Veselin Vasilev
Telerik team
answered on 26 Sep 2009, 11:10 AM
Hello Doug Arneson,

A RadListBoxItem object can exist in only one collection. So, you need to clone that item:

Protected Sub SetValue1(ByVal sender As ObjectByVal e As System.EventArgs)   
        Dim lbListBox As RadListBox = sender  
        Dim strItem As RadListBoxItem = lbListBox.SelectedItem   
  
        RadListBox3.Items.Add(strItem)   
        RadListBox3.ClearSelection()   
        RadListBox2.Items.Add(strItem.Clone())   
        RadListBox2.ClearSelection()   
End Sub 


Sincerely yours,
Veselin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Doug Arneson
Top achievements
Rank 1
answered on 26 Sep 2009, 11:19 PM
Veselin,

That did the trick. I thought the answer was easy, thanks for the quick response.

Doug

Tags
ListBox
Asked by
Doug Arneson
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Doug Arneson
Top achievements
Rank 1
Share this question
or