Fiur
Fiur

Reputation: 632

Windows CE textbox Focus problem

I have a problem setting the focus back to a textbox. I run the same application both on Windows Ce and Windows Mobile 5 and the issue is only on WinCE. On a form i have a custom control (let's say a custom DropDown) and a textbox, after an item is selected in the custom control i want to pass the focus back to the textbox.

The code looks like this:

private void ddlCurrencyList_SelectedItemChanged(object sender, SelectedItemArgs e)
{
    _selectedCurrency = CurrencyCollection.Find(ddlCurrencyList.SelectedValue);
    txtTabValue.Focus(); //does not work on Win CE. 
}

I can't figure out what steals the focus on WinCe.

Upvotes: 0

Views: 2456

Answers (2)

Simon Unsworth
Simon Unsworth

Reputation: 340

A bit late to the party, but I did this in Win CE 5, in 'C' I was trying to intercept the enter key, and found that this work for my case.

......
         case IDOK: // fall through
                    //enter does this!
                    //It supposed to, now we need to know who the hell sent it
                    focus = GetFocus();
                    //get the focus and compare it to a possible focussed  object                
                    hctl_quantity = GetDlgItem(hwnd,IDC_EDIT_QUANTITY);
                    if (focus == hctl_quantity) {
                        //Enter is press in the quantity text field
                        //Update quantity for this tag

                        //Generate Request Object

                        //Send Object, get response

                        //Check Response

                    }

                    break;

Upvotes: 0

Thorsten Dittmar
Thorsten Dittmar

Reputation: 56697

I would guess that the list regains the focus after calling the event. Maybe it would help to invoke the call to txtTabValue.Focus() in a separate thread that just waits a couple of milliseconds and then calls txtTabValue.Focus() in the thread context of the form? Seems a bit over the top but might work - strange things happen when using the Compact Framework ;-)

Upvotes: 0

Related Questions