SelectedItem is Nothing when Text = "" (bug?)

4 posts, 0 answers
  1. Marcus
    Marcus avatar
    17 posts
    Member since:
    Aug 2012

    Posted 13 Dec 2011 Link to this post

    Hi,

    When I set the Text property of one of the items to a Null string ("") and it's selected then the SelectedItem property of the DDL gives a Nothing value. If I set the Text property to f.e. 1 space (" ") then I don't have this problem.

  2. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 15 Dec 2011 Link to this post

    Hi Marcus,

    Thank you for writing.

    I cannot reproduce the issue with my test project - please refer to the code snippet below:

    Private Sub Form2_Load( sender As System.Object,  e As System.EventArgs) Handles MyBase.Load
        for i =0 to 10
                me.RadDropDownList1.Items.Add("Item "&i)
        Next i
        me.RadDropDownList1.Items(4).Text=""
    End Sub
    When I select Item(4), the SelectedItem is not Noting.

    Please check if I have not followed your description correctly and modify the code in a way to demonstrate the issue. This will allow me to assist you further with a workaround if such is available.

    I am looking forward to your reply.

    All the best,
    Peter
    the Telerik team

    Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Marcus
    Marcus avatar
    17 posts
    Member since:
    Aug 2012

    Posted 19 Dec 2011 Link to this post

    Please try the code below. In my case it will raise an error:

    RadDropDownList1.Items.Add("")
    RadDropDownList1.SelectedIndex = 0
     
    MessageBox.Show(RadDropDownList1.SelectedItem.Text)

  5. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 21 Dec 2011 Link to this post

    Hi Marcus,

    I was able to reproduce the described issue.

    We will provide fix for it in our next release. Currently, as a workaround you should set DropDownList's Text property to "" . Please refer to code below:

    RadDropDownList1.Text = ""
    RadDropDownList1.Items.Add("")
    RadDropDownList1.SelectedIndex = 0
    MessageBox.Show(RadDropDownList1.SelectedItem.Text)

    I hope this helps.

    Kind regards,
    Peter
    the Telerik team

    Q3’11
    of RadControls for WinForms is available for download (see what's new). Get it today.
Back to Top