Text property not set correctly using AutoComplete

4 posts, 1 answers
  1. Mark
    Mark avatar
    6 posts
    Member since:
    Jun 2010

    Posted 05 Jun 2012 Link to this post

    Hi,

    I have a RadComboBox defined as follows:

    <telerik:RadComboBox
        ID="ddlValue"
        runat="server"
        AllowCustomText="True"
        Width="320px"
        MarkFirstMatch="True"
        AutoCompleteSeparator=";"
        AutoPostBack="true"
        OnSelectedIndexChanged="ddlValue_SelectedIndexChanged">
    </telerik:RadComboBox>

    And this code-behind
    
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            var datasource = new RadComboBoxItemCollection(ddlValue)
            {
                new RadComboBoxItem("", ""),
                new RadComboBoxItem("David Larkin", Guid.NewGuid().ToString()),
                new RadComboBoxItem("Ahmed Warreth", Guid.NewGuid().ToString()),
                new RadComboBoxItem("Ryan Estes", Guid.NewGuid().ToString()),
                new RadComboBoxItem("Antonio Siqueira", Guid.NewGuid().ToString())
            };
     
            ddlValue.DataSource = datasource;
            ddlValue.DataTextField = "Text";
            ddlValue.DataValueField = "Value";
            ddlValue.DataBind();
        }
    }
     
    protected void ddlValue_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        ltrSelection.Text = (sender as RadComboBox).Text;
    }
    I'm experiencing the following behaviour:
    1. Choose David Larkin from the combo box
    2. David Larkin appears in the label as expected
    3. Place the cursor in the combo box at the end of the text, type ";Ah" and press Enter
    4. David Larkin;Ahmed Warreth appears in the label as expected
    5. Choose the first item in the combo box
    6. I would expect the text of the combo box to become an empty string, but it is actually "David Larkin;"

    Is there some property that I'm not setting that would cause this, or is it a bug in the control?

    I'm using version 2011.1.413.40.

    Thanks,

    David
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 05 Jun 2012 Link to this post

    Hi Mark,

    This is the default behavior in RadComboBox. As a work around you can try the following code snippet.

    C#:
    protected void ddlValue_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            string txt = (sender as RadComboBox).Text;
            if (ddlValue.SelectedItem == null)
            {
                string[] st = txt.Split(';');
                if (st != null)
                {
                    ltrSelection.Text = "";
                    ddlValue.Text = "";
                }
            }
            else
            {
                ltrSelection.Text = txt;
            }
        }

    Hope this helps.

    Thanks,
    Princy.
  3. Mark
    Mark avatar
    6 posts
    Member since:
    Jun 2010

    Posted 05 Jun 2012 Link to this post

    Thanks very much Princy, that seems to do the trick.
  4. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 06 Jun 2012 Link to this post

    Hi Mark,

    Glad to help you.

    Regards,
    Princy.
Back to Top