Click here to Skip to main content
15,907,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
am having three cells i.e,cell-1,cell-2,cell-3 in datagridview..here i wanna to focus on cell-1 while wrong data entered on it instead focus move on next cell...

In my coding i set msgbox alert while null values are enter...My question is How to focus on current cell instead of moving to next cell during wrong data entries in that cell

thanks in advance
Posted
Updated 4-Jul-11 0:33am
v6
Comments
reid0588 4-Jul-11 7:04am    
what do you want to do when you focus on the cell? or would you like the incorrect data to be highlighted?
e.g say in cell-1 the value should be 11 however the value entered is 14, do you want the cell to be highlighted to inform the user that the information is correct?
Nathansathya 4-Jul-11 7:17am    
hi reid,
if am enter wrong data in cell-1 the focus will remain on the same cell(cell-1) while am pressing 'tab'..
for eg: 2 is the correct value for cell-1 but i entered 3 and press 'tab'..at that time focus will remains in same cell(cell-1) itself instead of move to cell-2......

1 solution

Hi,

Use CellValidating event of DataGridView to validate cell values.

Steps:
- Use DataGridView's CellValidating event,
- Get the cell for which the event is called,
- If the cell is in EditMode then,
- Perform validation.

http://msdn.microsoft.com/en-us/library/ykdxa0bc.aspx[^]

Hope that helps... :)

Jasmin
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900