Q

How can I update the Data Grid so it will not affect focus?

I am trying to make an application which will download records to a Data Grid in the background, similar to the way e-mail appears in Outlook. I have this bound to a Data Grid, and for argument sake, let's say I have a timer that appends a record to dataset once per second.

So far so good; it works as expected -- except the Data Grid steals focus each time the timer fires. If I am on another form, or control, suddenly I am sitting on the grid!

I would like the record to appear without affecting focus. Any idea how to update the Data Grid so it will not affect focus?

I hate thieves, especially those that steal focus! What you're going to need to do in the timer event handler is get the control that has focus on the form (System.Windows.Forms.Control.Controls[].Focused) and save it off. After you do your updating, call the Control.Focus() method to reset the control back.

Of course, the default Data Grid control is not so perfect and there's no easy way to keep it from stealing focus. If it still steals focus and refuses to update in the background, you may be better off looking at one of the third party grid controls.

This was first published in June 2004

Dig deeper on Windows Operating System Management

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchServerVirtualization

SearchCloudComputing

SearchExchange

SearchSQLServer

SearchWinIT

SearchEnterpriseDesktop

SearchVirtualDesktop

Close