• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 986
  • Last Modified:

Focus control after grid binding - .net compact framework

Experts,

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;

                frmRequestDetail.Close();

                frmRequestDetail.Dispose();

                dtDetails.Rows.Add(dr);

                dgDetails.DataSource = dtDetails;

                txtSN.Text = "";

                txtSN.Focus();
            }

Open in new window


Thank you
0
mdoyon
Asked:
mdoyon
  • 2
1 Solution
 
Roopesh ReddyCommented:
Hi,

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 - http://stackoverflow.com/questions/920142/windows-ce-textbox-focus-problem

Hope it helps u...
0
 
mdoyonAuthor Commented:
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
0
 
mdoyonAuthor Commented:
Found solution.
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now