HighTechTalks DotNet Forums  

Preventing focus from leaving DataGridView

Dotnet Framework (WinForms Controls) microsoft.public.dotnet.framework.windowsforms.controls


Discuss Preventing focus from leaving DataGridView in the Dotnet Framework (WinForms Controls) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Larry
 
Posts: n/a

Default Preventing focus from leaving DataGridView - 12-24-2007 , 06:31 PM






Hi,

I need to prevent a user from moving away from a DataGridView if it contains
invalid data.

Some specifics: The user should be able to move within the specific grid,
but not move to any other control on the form (including any other grid on
the form). I have tried a number of methods, for example:
1) From the Leave event of the grid: Set focus back to the grid (with and
without also calling BeginEdit)
2) From the RowValidating, set cancel = true if invalid data
3) From CellValidating, set cancel = true if invalid data

None of the above prevents the user from leaving the grid.

I could get it to work by trapping the Enter event on all other controls on
the form and setting focus back to the grid in question as needed from
there, but there must be a better way than that.

Does anyone know of a cleaner method to accomplish this?

Thanks,
Larry





Reply With Quote
  #2  
Old   
Colin Han
 
Posts: n/a

Default Re: Preventing focus from leaving DataGridView - 12-27-2007 , 04:02 AM






Hi, Larry,
My English is poor. I just write solution for my understanding. If you has
more question. Can discuss with me continus.

If you want control can not leave focus, you should handle Validating
event to set e.Cancel to true.
So, user can move current cell in this dataGridView. but he can not set
the focus to other controls. And the application will cannot to close.

"Larry" <nomail (AT) dev (DOT) null> wrote

Quote:
Anyone??





Reply With Quote
  #3  
Old   
Jeff Gaines
 
Posts: n/a

Default Re: Preventing focus from leaving DataGridView - 12-27-2007 , 04:17 AM



On 27/12/2007 in message <13n6lh5ldl99p25 (AT) corp (DOT) supernews.com> Larry wrote:

Quote:
Anyone??
What about capturing the Validating event and restoring focus if the data
is not valid?

--
Jeff Gaines


Reply With Quote
  #4  
Old   
Larry
 
Posts: n/a

Default Re: Preventing focus from leaving DataGridView - 12-27-2007 , 01:26 PM




Quote:
What about capturing the Validating event and restoring focus if the data
is not valid?
Tried that - does not work (but you'd think it would - not sure why it does
not). Seems like an oversight in the design of the grid that this should be
so hard...

Larry




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.