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

problem with SelectedItem

4 Answers 217 Views
ListControl
This is a migrated thread and some comments may be shown as answers.
mike
Top achievements
Rank 1
mike asked on 24 Aug 2011, 01:01 PM
Hi I was using the following with a standard listBox

Private Sub RadListControl1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.Data.PositionChangedEventArgs) Handles RadListControl1.SelectedIndexChanged
        If RadListControl1.SelectedIndex > -1 Then
            Dim tenants As Tenant = RadListControl1.SelectedItem
 
            RadTextBox5.Text = tenants.ID
            RadTextBox6.Text = tenants.FirstName
            RadTextBox7.Text = tenants.Existing
            RadTextBox8.Text = tenants.LastName
 
        End If
    End Sub

however when I try to use the RadListControl I get an error on this line
Dim tenants As Tenant = RadListControl1.SelectedItem
error Value of Type telerik.win.controls.UI.RadListDataItem ' cannot be converted to mainSystem.Tenant?

please advise

4 Answers, 1 is accepted

Sort by
0
Ivan Petrov
Telerik team
answered on 29 Aug 2011, 12:03 PM
Hi Mike,

Thank you for writing.

You have to use the RadListControl, SelectedValue property or SelectedItem.Value if you want to retrieve the value of the item you have set. 

I hope this will help. If you have further questions, I would be glad to assist.

All the best,
Ivan Petrov
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
mike
Top achievements
Rank 1
answered on 29 Aug 2011, 05:36 PM
But I am using RadListControl1.SelectedItem and that is giving me an error ? if I try selectedValue it doesn't work? it works fine with a windows listBox control?
0
mike
Top achievements
Rank 1
answered on 29 Aug 2011, 05:40 PM
But I am using RadListControl1.SelectedItem and that is giving me an error ? if I try selectedValue it doesn't work? it works fine with a windows listBox control?

When I use

Dim tenants As Tenant = RadListControl1.SelectedValue or 
Dim tenants As Tenant = RadListControl1.SelectedItem.Value

I get Unable to cast object of type 'System.String' to type 'Tenant'.
0
Ivan Petrov
Telerik team
answered on 01 Sep 2011, 08:37 AM
Hello Mike,

Thank you for your reply.

I have attached a sample application where I have tried to implement a scenario like yours. The RadListControl works a bit differently compared to the standard ListBox. The standard ListBox uses the ToString method of a class to display text for each item. The RadListControl items are composed of text and value. The text is the string displayed on the item and the value is the actual data. 

I hope this will clarify how the RadListControl works. If you have other questions do not hesitate to write back.

Regards,
Ivan Petrov
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
ListControl
Asked by
mike
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
mike
Top achievements
Rank 1
Share this question
or