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

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

3 Answers 70 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Marcus
Top achievements
Rank 1
Marcus asked on 13 Dec 2011, 10:22 AM

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.

3 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 15 Dec 2011, 05:07 PM
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.

0
Marcus
Top achievements
Rank 1
answered on 19 Dec 2011, 04:55 PM

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

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

0
Peter
Telerik team
answered on 21 Dec 2011, 03:28 PM
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.
Tags
DropDownList
Asked by
Marcus
Top achievements
Rank 1
Answers by
Peter
Telerik team
Marcus
Top achievements
Rank 1
Share this question
or