Disable Editing in radcombobox

Thread is closed for posting
2 posts, 0 answers
  1. Mateo
    Mateo avatar
    5 posts
    Member since:
    Aug 2009

    Posted 16 Sep 2009 Link to this post

    I have a combobox defined like this:

    cmbOrigin.AutoCompleteMode = AutoCompleteMode.SuggestAppend;  
    cmbOrigin.NullText = Transat.PDP.Client.Properties.Resources.ControlDataOriginNullText;  
    foreach (MyItem i in ListOfMyItems)  
        cmbOrigin.Items.Add(new RadComboBoxItem(string.Format("{0} - {1}", i.Code, i.Nom), i));  

    I want to have the AutoCompleteMode set to SuggestAppend so that the rest of the text get showed and the list is showed too.
    What i dont want is the user to be able to type 2 letters and then hit backspace and go out of the combobox leaving me with an inconsistant value.

    how can i force the user to pick a valid entry in the combobox?


  2. Deyan
    Deyan avatar
    2147 posts

    Posted 23 Sep 2009 Link to this post

    Hi Mateo,

    Thanks for writing and for your question.

    First, I would like to apologize for the delay with my answer due to a couple of national holidays here.

    Back on your question.

    I guess using the KeyDown event of the RadComboBox control and deselecting the input of the user upon clicking on the Backspace key would do the job. Take a look at the code snippet below:

     private void OnRadComboBox_KeyDOwn(object sender, KeyEventArgs e) 
                if (e.KeyData == Keys.Back) 
                    this.radComboBox1.Select(0, 0); 

    Basically, this code will deselect any selected text in the RadComboBox control when you click the Backspace key and thus will prevent you from deleting this text. In the case of the SuggestAppend mode, this will leave a valid input in the RadComboBox control as you require.

    I hope this is helpful.

    You can write back anytime you need further assistance though.

    All the best,
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top