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

Setting RadDropDownList to NoSelection in code

7 Answers 847 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Baldwin
Top achievements
Rank 1
Baldwin asked on 30 Aug 2010, 02:59 PM
Hello everybody.

I have a problem with rad drop downlist.
My drop down list is unbound and populated during runtime, every item having text and value.
A valid value to be displayed should be 'no selection' => SelectedValue = null
The selected item should change after the selected node in a tree view is changed

When I first select item which have null as value for the drop down list, everything's ok.
But after an entry from the DrowDownList was selected and the try to change the SelectedValue to null, I have the problem, that even though the SelectedValue seems to be null, the text of the last selected item is still displayed.

I tried setting the value to NULL by using:
  • SelectedValue = null;
  • SelectedIndex = -1;
  • SelectedItem = null;

All produced the same result: The SelectedValue is null when I check, but there is still text displayed.
So, my question is: how can I reset the DropDownList to a state where no item is selected by code.

Thanks for any help

7 Answers, 1 is accepted

Sort by
0
NORIS
Top achievements
Rank 1
answered on 30 Aug 2010, 07:22 PM
I experienced a similar problem.  I was able to resolve it by closing the the DropDown first and resetting the SelectedIndex and Text.
Hope this helps.

RadDropDownList1.CloseDropDown() 'get exception error or empty items in list if DropDown is open
RadDropDownList1.SelectedIndex = -1 'keeps selected, even when no longer in list
RadDropDownList1.Text = "" 'keeps text even when nothing in list
0
Baldwin
Top achievements
Rank 1
answered on 31 Aug 2010, 10:14 AM
Thanks NORIS.

The workaround helps, though in my tests, setting the Text-Property to String.Empty was sufficient. CloseDropDown() was not required.

Still, I would like to know if there's an official way?

Thanks again
0
NORIS
Top achievements
Rank 1
answered on 31 Aug 2010, 01:17 PM
I was told this is fixed in the lastest IB.
0
Peter
Telerik team
answered on 02 Sep 2010, 11:25 AM
Hello,

Thank you for contacting us.

We are aware of the issue with the deletion of items and RadDropDownList should update itself when selected item is null. This has been fixed in the latest internal build released on Aug 25. You can download this build from Your Account >> Downloads >> RadControls for WinForms >> Latest Internal Builds. The version of the build is v2010.2.10.825.

Do not hesitate to contact us if you have additional questions.

Best wishes,
Peter
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Baldwin
Top achievements
Rank 1
answered on 06 Sep 2010, 12:35 PM
Thanks.

I will try out the internal build when I find time.
Meanwhile, I have another partly related question about a problem with a bound drop down list:

In this case, I have a bound drop down list which is in DropDown-Mode, thus allowing manual input.
Now, an item is selected (SelectedValue is e.g. 1) and after that text is entered in the input field by the user.
If the entered string is confirmed with Enter-Key, SelectedValue changes to Null (which was what I expected), but if the user leaves the input field without hitting Enter key, the SelectedValue stays at 1. I would like that the SelectedValue property also changes to null in that case.

I considered using the TextChanged event but the event does not seem to fire for some reason.

Is there a solution to this?
0
Peter
Telerik team
answered on 08 Sep 2010, 06:09 PM
Hi,

Thanks for the provided details.

You can subscrube for TextBox's TextChanged event:
 
this.radDropDownList1.DropDownListElement.TextBox.TextChanged += new EventHandler(TextBox_TextChanged);
 
We will include a fix for Control's TextChanged event in one of our next releases.
 
Don't hesitate to contact us if you have other questions.

Regards,
Peter
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Baldwin
Top achievements
Rank 1
answered on 09 Sep 2010, 08:30 AM
Thanks for the advice.
That was indeed something I'd not have thought of.
Tags
DropDownList
Asked by
Baldwin
Top achievements
Rank 1
Answers by
NORIS
Top achievements
Rank 1
Baldwin
Top achievements
Rank 1
Peter
Telerik team
Share this question
or