Focus control after grid binding - .net compact framework

Posted on 2012-08-24
Last Modified: 2012-09-02

I'm having an issue focusing a control after rebind of a grid.

Here is the order of events:

Open modal dialog
on dialog result ok, close and dispose dialog
add record to grid's datasource
call function to set grids datasource to the list
set focus to a textbox below the grid.

My issue occurs when i try to set focus to the textbox. On an emulator this works fine, but when deployed to the handheld, focus is set to the first row and first column of the grid, even after focus has been called on the textbox.

Code sample below:

            if (frmRequestDetail.DialogResult == DialogResult.OK)
                DataRow dr = frmRequestDetail.RequestDetailRow;




                dgDetails.DataSource = dtDetails;

                txtSN.Text = "";


Open in new window

Thank you
Question by:mdoyon
    LVL 23

    Expert Comment

    by:Roopesh Reddy

    You'r code is correct and it should work!

    Did you tried removing the app completely  in device and reinstalling it?

    Also, check this link -

    Hope it helps u...

    Accepted Solution

    The issue stems from making this call inside of the KeyDown event.

    We are capturing the tab key, but never telling the event that the tab key press has been handled. After all code inside the event is executed (Including the textbox.Focus()) the tab key press is handled.

    To remedy this situation, you must tell the event that the key press has already been handled:

    e.Handled = true;

    Open in new window

    Simple solution to a three day problem. Still strange that it should work on an emulator and not on a device.

    Thank you

    Author Closing Comment

    Found solution.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Suggested Solutions

    This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now