This is a migrated thread and some comments may be shown as answers.
Can't move last item in RadListBox
1 Answer 94 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
DGraham asked on 28 Aug 2009, 03:48 PM

The items transfer fine between the two list boxes unless its the last item in the list box, where I get the following error:

Error occurs on first line of RadListBoxContacts_Transferred (VB code)

'Object reference not set to an instance of an object.'

 please see code below:

<telerik:RadListBox ID="RadListBoxContacts" runat="server" Skin="Telerik" AutoPostBack="true" 
                                                                AutoPostBackOnTransfer="true" DataKeyField="contactID" DataTextField="Description" 
                                                                Width="240px" Height="200px" AllowTransfer="true" TransferToID="RadListBoxServiceContacts" 
                                                                ButtonSettings-ShowTransferAll="false" EnableViewState ="true">  
                                                                <ButtonSettings ShowTransferAll="False" /> 
<telerik:RadListBox ID="RadListBoxServiceContacts" runat="server" Skin="Telerik" 
                                                                DataKeyField="contactID" DataTextField="Description" Width="245px" Height="200px" 
                                                                AutoPostBack="True" EnableViewState ="true" > 

Private Sub RadListBoxServiceContacts_Deleted(ByVal sender As ObjectByVal e As Telerik.Web.UI.RadListBoxEventArgs) Handles RadListBoxServiceContacts.Deleted  
        Session("Avalability") = "Delete" 
        Me.lblServiceContactDescription.Text = "Select a contact to view details" 
        Me.lblServiceContactDetails.Text = "" 
    End Sub 
    Private Sub RadListBoxServiceContacts_Inserted(ByVal sender As ObjectByVal e As Telerik.Web.UI.RadListBoxEventArgs) Handles RadListBoxServiceContacts.Inserted  
        Session("Avalability") = "Insert" 
        Me.lblContactDescription.Text = "Select a contact to view details" 
        Me.lblContactDetails.Text = "" 
    End Sub 
    Private Sub RadListBoxContacts_Transferred(ByVal sender As ObjectByVal e As Telerik.Web.UI.RadListBoxTransferredEventArgs) Handles RadListBoxContacts.Transferred  
        Dim contactID As String = CStr(e.SourceListBox.SelectedItem.DataKey)  
        Dim serviceID As String = CStr(Me.RadListBoxServices.SelectedItem.DataKey)  
        If CStr(Session("Avalability")) = "Delete" Then 
            objWebService.removeContactFromService(contactID, serviceID)  
        ElseIf CStr(Session("Avalability")) = "Insert" Then 
            objWebService.addContactToService(contactID, serviceID)  
        End If 
        Me.RadListBoxServiceContacts.DataSource = objWebService.getServicesContacts(CInt(Me.RadListBoxServices.DataKeys.Item(Me.RadListBoxServices.SelectedIndex)))  
        Me.RadListBoxContacts.DataSource = objWebService.getEmployeeContactsNotInService(CInt(Me.RadListBoxServices.DataKeys.Item(Me.RadListBoxServices.SelectedIndex)), Me.RadComboBoxSelectedEmployee.SelectedValue, "")  
    End Sub 

The last four lines are executed in the Page_Load to initially populate the list boxes

As can be seen above the list boxes are re-bound to the database via a web service every time an item is inserted or deleted.

Any help or pointes in the right direction would be great.

Many Thanks.

1 Answer, 1 is accepted

Sort by
Genady Sergeev
Telerik team
answered on 04 Sep 2009, 08:51 AM
Hello DGraham,

The Transferred event fires when an item is already transferred. This means that the item is removed from the source and is added to the destination. Then the next item in the source is selected so that you can proceed with the transfer. However, when the last item is being transferred, there are no more items to select in the source hence the null reference error. I suggest you to use the e.Items collection to obtain the items being transferred.


Sub RadListBoxContacts_Transferred(sender As Object, e As RadListBoxTransferredEventArgs) 
    Dim item As RadListBoxItem = e.Items(0) 
End Sub 

I hope this helps.

Kind regards,
Genady Sergeev
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.
Asked by
Top achievements
Rank 1
Answers by
Genady Sergeev
Telerik team
Share this question