Click here to Skip to main content
16,012,223 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a grid which has 4 columns.
Leaving a column blank is not allowed but you can go to the upper row columns(which are filled).
Some columns are mandatory which are checked by a validating function.

If the conditions are satisfied for the current row(validating function), go to the next row(downwards/upwards)
If the conditions are not satisfied(validating function) then dont go the next row downwards.But if you click the upper row then you should be able to go there.

Thanks in advance.
Posted
Comments
Brett Caswell 16-Jan-11 10:40am    
your question is too vague, I don't know what you're trying to accomplish exactly.

whatever you're trying to accomplish, I'm sure the key to it will be working with the proper events, as they are raised.

DataGridViews are notoriously difficult to use in real life end-user applications. This is because the customer always wants to validate a photon of the data before committing it to wider audience. If you want to validate the cell contents before moving in any direction within the grid you have a problem fullstop, because it is not just tab keys you have to worry about, it is mouse movements and up/down arrows.

Because of these limitations, the experienced developer avoids the traps of the real-time Excel UI that customers usually understand and opt for a separate field representation of the data in the row or column involved. This allows us to enforce and police business process integrity and validation, before committing the change to the database in a multi-user environment.

Design and ergonomics are essential facets of any development. So always question the question, when it gets difficult!
 
Share this answer
 
Assuming you are talking about a PC program's DataGridView...

If you are trying to protect the data inside the grid you can make the column read-only.

If you are trying to move focus on a protected cell you could try using SendKeys with a Tab or Enter key or down key. I have used this in the past but it's not ideal. I know some anti-virus applications have a problem with programs using sendkeys...but it was for a not-so-very important part of my project and so I've never taken the time to research a better way.

Here is how I use it in my program (my validating function is just if the cell is read-only or not):

VB
Private Sub dgvGrid_CellEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvGrid.CellEnter
       If dgvGrid.Columns(e.ColumnIndex).ReadOnly Then
           SendKeys.Send("{Tab}") 'Tabs out of the read only column, so user will never be able to select it
       End If
   End Sub


I hope this helps.
 
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