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

Text property not set correctly using AutoComplete

3 Answers 51 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 05 Jun 2012, 10:16 AM
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

3 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 05 Jun 2012, 10:44 AM
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.
0
Mark
Top achievements
Rank 1
answered on 05 Jun 2012, 11:39 AM
Thanks very much Princy, that seems to do the trick.
0
Princy
Top achievements
Rank 2
answered on 06 Jun 2012, 09:54 AM
Hi Mark,

Glad to help you.

Regards,
Princy.
Tags
ComboBox
Asked by
Mark
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Mark
Top achievements
Rank 1
Share this question
or