DataGridView - Cell Validation/Focus

Posted by Admin on 21-Mar-2011 23:03

Hi,

I have inherited some GUI for .Net code and am somewhat new to the .Net world.

I have a DataGridView, which i want to validate the user entered data as he/she leaves the cell.

My question is how to return the cursor to the cell in the DataGridView if the data is not valid.

Here is the code that does the validation. Any help appreciated.

@VisualDesigner.

METHOD PRIVATE VOID TaskDashBrowse_CellValidated( INPUT sender AS System.Object, INPUT e AS System.Windows.Forms.DataGridViewCellEventArgs ):

define variable dgv AS System.Windows.Forms.DataGridView.

     if e:columnindex = 2 then do:

          dgv =

cast( sender, System.Windows.Forms.DataGridView).

          if myApplication:UserExists ( dgv:CurrentCell:Value:ToString() ) = false then do:

               message "User does not exists within QAD" view-as alert-box error.

               /* how do i keep the cursor in the current cell?? */

               return.

          end.

     end.

     case e:ColumnIndex:

          when 2 or when 4 or when 8 then do:

               TheTaskDashBindSource:

Assign().

          end.

     end.

     RETURN.

END METHOD.

Progress 10.2B

All Replies

Posted by Admin on 22-Mar-2011 05:06

Try handling the before event: CellValidating rather than CellValidated.

As a side note, rather than using the ToString() method on the Cell's Value property use the ABL UNBOX function. ToString() sometimes does not return what you want.

Also, rather than using numerical indexers to access you cells, try character ones which is independent from the order.

This thread is closed