problem with SelectedItem

5 posts, 0 answers
  1. mike
    mike avatar
    3 posts
    Member since:
    Aug 2011

    Posted 24 Aug 2011 Link to this post

    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
  2. Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 29 Aug 2011 Link to this post

    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 >>

  3. UI for WinForms is Visual Studio 2017 Ready
  4. mike
    mike avatar
    3 posts
    Member since:
    Aug 2011

    Posted 29 Aug 2011 Link to this post

    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?
  5. mike
    mike avatar
    3 posts
    Member since:
    Aug 2011

    Posted 29 Aug 2011 Link to this post

    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'.
  6. Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 01 Sep 2011 Link to this post

    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 >>

Back to Top
UI for WinForms is Visual Studio 2017 Ready