views:

16

answers:

2

Hi,

I am using a Autocomplete textbox for "like" search text from Database using KeyDown Event. One of the scenario is COPY-PASTE textname to Autocompletebox where data is already available in Database.

I was unable to complete this scenario because when i am trying to paste the text, "Ctrl" is getting fired instead of "Ctrl+V" from kepboard.

Here is the code for your reviews

string a = autoCompleteBox2.Text + e.Key.ToString().ToLower();


        if (FirstKey.Equals("ctrl") && string.IsNullOrEmpty(e.Key.ToString()))
        {
            a = autoCompleteBox2.Text;
        }

        if (!string.IsNullOrEmpty(a) && a.Length > 0 && !CurrentKey.Equals("ctrl"))
        {
            pvm.SearchDrug(4, a);
        }
        FirstKey = e.Key.ToString().ToLower();

this event is taking "Ctrl" instead of "Ctrl+ V".

Please help me regarding this.

Thanks, Srinivasa

A: 

You shouldn't be using the KeyDown event to trigger search in an AutoCompleteBox. Please refer to the incredibly helpful post "AutoCompleteBox - The Missing Guide" by Jeff Wilcox.

The event you want is Populating, which will fire regardless of whether the text is typed or pasted and respects the delayed reaction, minimum length, etc.

Josh Einstein
A: 

Hi,

I have similar type of problem. I am using mvvm pattern. I bounded the ObservableCollection to display the autocomplete value. When user enters 2nd character need to fetch TOP 20 records from database and display under autocomplete dropdown.

Here when I enter data says 'me', it fetching the top 20 data and stores the under the ObserverableCollection. But it’s not displaying under autocomplete box dropdown. When I start type 3rd character its filters out of that collection and display that records. Can anyone give solution to resolve the problem?

And same thing happens when I copy/paste the text. Say I pasted 3 characters like 'met’, data stores under collection in VM. But not displaying under the control. (Note: I'm using TwoWay binding for autocomplete ItemSource and passing text value to service to fetch data at KeyUp event). If I enter the 4th character then it filter out of that 20 record and displays.

skumar