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

Which event to subcribe when user clicks on drop down list from textbox auto complete suggestions

3 Answers 182 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
Pratik
Top achievements
Rank 1
Pratik asked on 16 Oct 2012, 04:43 AM
I have a RadTextBoxControl (or RadAutoCompleteBox). When the user types some text the drop down list of text suggetsions appears below. I want to capture the event when user clicks on one of the items from the list to select it. Which event should I subscribe to catch this. I also want to do the same if they tab out from the box.

3 Answers, 1 is accepted

Sort by
0
Svett
Telerik team
answered on 18 Oct 2012, 02:25 PM
Hi Pratik,

You can handle when the user click on item from the auto-complete drop down list by handling the Click event in the following manner:
this.radTextBoxControl1.ListElement.ElementTree.Control.Click += this.OnListElementClick;

private void OnListElementClick(object sender, EventArgs e)
{
    ComponentThemableElementTree elementTree = this.radTextBoxControl1.ListElement.ElementTree;
    Point mousePosition = elementTree.Control.PointToClient(Control.MousePosition);
    RadElement element = elementTree.GetElementAtPoint(mousePosition);
 
    while (element != null)
    {
        RadListVisualItem item = element as RadListVisualItem;
 
        if (item != null)
        {
            // YOUR LOGIC HERE
            break;
        }
 
        element = element.Parent;
    }
}

If you want to handle when the user press TAB key, you should subscribe for KeyDown event of RadTextBoxControl (RadAutoCompleteBox):
this.radTextBoxControl1.KeyDown += new KeyEventHandler(radTextBoxControl1_KeyDown);

private void radTextBoxControl1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Tab)
    {
        // YOU LOGIC
    }
}

I hope this helps.
 
Regards,
Svett
the Telerik team
You’ve been asking for it and now it’s time for us to deliver. RadControls for WinForms Q3 2012 release is just around the corner. Sign up for a free webinar to see first all the latest enhancements.
0
Anders
Top achievements
Rank 1
answered on 29 Jan 2016, 08:43 AM
RadAutoCompleteBox.ListElement does not exist, was this answer only about RadTextBoxControl?
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 02 Feb 2016, 12:13 PM
Hello Anders,

Thank you for writing.

The RadAutoCompleteBox.ListElement property is available in the latest official release Q1 2016. You can find attached a sample project demonstrating how to detect when autocomplete popup is clicked.

I hope this information helps. Should you have further questions I would be glad to help.
 
Regards,
Dess
Telerik

Tags
AutoCompleteBox
Asked by
Pratik
Top achievements
Rank 1
Answers by
Svett
Telerik team
Anders
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or