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

limiting tokens in radautocompletebox

3 Answers 60 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
ahmed
Top achievements
Rank 1
ahmed asked on 12 Mar 2018, 09:18 PM
I want to limit the numbers of tokens the user can add to the box to 1 token item only after that he can't enter any more letters

3 Answers, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 13 Mar 2018, 09:22 AM
Hi Ahmed,

You can use the KeyPress event and check the items count:
private void RadAutoCompleteBox1_KeyPress(object sender, KeyPressEventArgs e)
{
    var el = sender as RadAutoCompleteBox;
    if (el.Items.Count > 0)
    {
        e.Handled = true;   
    }
}

Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
ahmed
Top achievements
Rank 1
answered on 13 Mar 2018, 11:11 AM
it works but the user can still paste text through Ctrl + v , Shift + INSERT and right click paste option how to stop the user from doing so ?
0
Accepted
Dimitar
Telerik team
answered on 14 Mar 2018, 07:26 AM
Hello Ahmed,

To handle these cases you can use the TextChanging event. The following example allows you to delete the existing token only:
private void RadAutoCompleteBox1_TextChanging(object sender, Telerik.WinControls.TextChangingEventArgs e)
{
    if (e.NewValue == "")
    {
        return;
    }
    var el = sender as RadAutoCompleteBox;
    if (el.Items.Count > 0)
    {
        e.Cancel = true;
    }
}

Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
AutoCompleteBox
Asked by
ahmed
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
ahmed
Top achievements
Rank 1
Share this question
or