简体   繁体   中英

How to make telerik autocomplete text box to accept only 1 entry in c# winforms

我正在使用 rad 自动完成文本框。我想在选择一个输入后只接受输入我必须禁用以免不接受任何输入,但我还需要删除该输入,以便用户可以删除以前的输入并输入其他输入.ie 我只需要完成 1 个选择。如果已经选择了该字段,则必须将该字段设为只读,如果我删除以前的选择,它应该可以再次编辑。

You can KeyPress event and check radAutoComplete text length and if more than one return it.

private void radAutoCompleteBox1_KeyPress(object sender, KeyPressEventArgs e)
{
    if (radAutoCompleteBox1.Text.Length > 0)
        e.Handled = true;
}

Also you can use this code for textBoxes , comboBoxes , etc.

图像

According to Telerik this is not possible, and that's correct, you can't stop the user "selecting" multiple entries, you can however prevent multiple entries from being "stored"

so when the user exists the auto complete field I remove all entries in the autocomplete box - except the first entered (and train the users) like so.

    private void stripmultientries()
    {
        // remove multi entries in the stock cat box ??? - leaver only the first
        string fulltext = radAutoCompleteBox1.Text;
        // remove everything after the first semi colon //
        int index = fulltext.IndexOf(";");
        if (index > 0)
        {
            fulltext = fulltext.Substring(0, index);
        }
        radAutoCompleteBox1.Text = fulltext;
    }

This method can be called when saving the form or when exiting the autocomplete control

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM