I am using the radCheckedDropDownList control with MultiLine set to True and AutoCompleteMode set to Suggest. When a user types text into the edit portion of the control and autocomplete fails to find a match the text remains in the edit portion upon leaving the control. If the user selects an item in the list the unmatched text string is removed when the drop down list is closed. Is there a way to either restrict the user entered text to the content of the checked drop down list or cause the edit portion of the control to refresh (remove the partial text) when a match is not found and the user leaves the control?
Thanks.
5 Answers, 1 is accepted
Thank you for writing.
You can prevent the user from entering invalid text in the editable part of the RadCheckedDropDownList by canceling the CheckedDropDownListElement.AutoCompleteEditableAreaElement.AutoCompleteTextBox.TextChanging event. Thus, you can check whether there are suggestions for the newly entered text.
I hope this information helps. Should you have further questions I would be glad to help.
Regards,
Dess
Telerik by Progress
Dess,
I have subscribed to the recommended event and created the following method stub. While this prevents the user from entering a character that does not match the first character of an item in the dropdown list, it prevents the user from selecting an item in the dropdown list by clicking on the checkbox. Another anomaly is that after typing in a character and then pressing Tab or Enter the selected item is not tokenized in the text box portion of the control (see attachment). Can you recommend coding changes to the event logic to resolve these issues? Also, I have the DropDownStyle property set to DropDownList which should prevent the user from typing in the text box portion of the control. Am I misunderstanding this property or is there an issue with the implementation of this property in the radCheckedDropDownList control?
private void TextBoxItem_TextChanging(object sender, TextChangingEventArgs e)
{
if (radCheckedDropDownList1.FindString(e.NewValue) == -1)
{
e.Cancel = true;
}
}
Phillip
Thank you for writing back.
You can handle the CheckedDropDownListElement.AutoCompleteEditableAreaElement.AutoCompleteTextBox.AutoCompleteDropDown.MouseDown event and detect whether a visual item is clicked. Afterwards, you shouldn't cancel the TextChanging event:
bool
shouldCancel =
true
;
private
void
AutoCompleteDropDown_MouseDown(
object
sender, MouseEventArgs e)
{
RadListVisualItem el =
this
.radCheckedDropDownList1.CheckedDropDownListElement.AutoCompleteEditableAreaElement.AutoCompleteTextBox.AutoCompleteDropDown.ElementTree.GetElementAtPoint(e.Location)
as
RadListVisualItem;
if
(el !=
null
)
{
shouldCancel =
false
;
}
}
I hope this information helps. If you have any additional questions, please let me know.
Regards,
Dess
Telerik by Progress
Dess,
In the attached image, you will see that upon leaving the control the user entered text is not cleared from the text box control. Is there a method that can be called to clean up the text box control so that only the selected item tokens (if any) are displayed?
Phillip
Thank you for writing back.
There isn't such a method that clears all the text that is not part of any token. However, you can handle the RadCheckedDropDownList.LostFocus event and iterate the CheckedItems collection and update the Text to contain only tokens:
private
void
radCheckedDropDownList1_LostFocus(
object
sender, EventArgs e)
{
string
delimiter =
this
.radCheckedDropDownList1.CheckedDropDownListElement.AutoCompleteEditableAreaElement.AutoCompleteTextBox.Delimiter;
StringBuilder sb =
new
StringBuilder();
foreach
(RadListDataItem item
in
this
.radCheckedDropDownList1.CheckedItems)
{
sb.Append(item.Text + delimiter);
}
this
.radCheckedDropDownList1.Text = sb.ToString();
}
I hope this information helps. If you have any additional questions, please let me know.
Regards,
Dess
Telerik by Progress