Link to home
Start Free TrialLog in
Avatar of rwheeler23
rwheeler23Flag for United States of America

asked on

Focus lost on lookup window using C# how to automatically focus on lookup window?

I am upgrading a Visual Studio 2015 C# application to VS 2019. Everything is working with this one exception. I have added a lookup button onto a datagridview. In the 2015 version I can start typing numbers and when the lookup grid appears I can immediately start typing and grid will match the first number then the second and so on and so on. In the 2019 version I need to click in the lookup grid first and then I can start typing. I have checked every event and they all match between both versions. What else can I check to determine why I need to manually focus first on the lookup window before I start typing numbers?

        private void dgvViewJobLinker_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 0 && e.RowIndex >= 0)
            {

                using (frmLookupJob ViewAgenciesByJobsForm = new frmLookupJob("Job_Linker"))    /* Send down formname "Job_Number" so it will return job number not customer number */
                {
                    if (ViewAgenciesByJobsForm.ShowDialog(this) == DialogResult.OK)
                    {
                        ViewAgenciesByJobsForm.Show();
                        ViewAgenciesByJobsForm.Activate();
                        ViewAgenciesByJobsForm.Focus();
                        dgvViewJobLinker[1, dgvViewJobLinker.CurrentCell.RowIndex].Value = ViewAgenciesByJobsForm.CellValue;
                    }
                }
            }
        }
Avatar of rwheeler23
rwheeler23
Flag of United States of America image

ASKER

I have attached the code for frmLookupJob
frmLookupJob.txt
Avatar of it_saige
Check and compare the properties of the DataGridView control between the two projects.

Also, is there any reason why you just didn't open the old project with VS 2019?  It shouldn't need to be uplifted/upgraded as since 2010/2013 all new versions are backwards compatible.

-saige-
This project is part of a much larger project part of which is the use of reflection. The VS 2015 version is my first attempt at reflection and has a lot of unnecessary code.  You know how programmers are. Always looking to make it tighter and more efficient. I just do not see differences and why I need to click on the grid first in the newer version. There is one small difference dealing with reflection but that code is needed. I may wind up checking with a reflection guru to see if he has any ideas.
Regardless of the reflection, VS 2019 will open a VS 2015 project without requiring an upgrade/uplift.  Most likely your issue stems from a control property not matching between the two projects.

-saige-
That is true. I have checked every property between the two and they are identical. There is one change that may have an impact here. I moved the call to the dataset and datagridview down into a method inside the lookup window. First thing tomorrow I will move it back and see if this corrects it.
You should also be able to determine if it is a VS 2019 thing by also opening the project, debugging and seeing if you get the same results.

-saige-
I do not know why but I had to add this.ActiveControl on the data grid view.

                DisplayAgenciesByJob();
                this.ActiveControl = dgvAgenciesByJobs;
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.