datagridview how to validate cell value

evolet10000

Active member
Joined
Nov 22, 2012
Messages
40
Programming Experience
Beginner
i have 2 datagridview, now i want to perform a input validation in each cell to know if the dgv2 value is greater than the dgv1 value

i used the ff code., and ofcourse it didnt work XD

Private Sub DataGridViewMC1_RIS_ISSUANCE_CellLeave(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridViewMC1_RIS_ISSUANCE.CellLeave
Dim issuance_qty As Integer = DataGridViewMC1_RIS_ISSUANCE.Rows(0).Cells(0).Value
Dim balanace_qty As Integer = DataGridViewMC1_RIS.Rows(0).Cells(5).Value
If issuance_qty > balanace_qty Then
MsgBox("The issuance quantity is greater than balance quantity of the supply")
End If
End Sub

i need to prompt the user that the cell value he/she enter(in dgv2) is greater than the balance quantity(in dgv1),.

any suggestion will be appreciated, and i will pray for you :D
 
You wouldn't handle CellLeave, but rather CellValidating. You can access the current cell by column and row index and do whatever is required to validate its contents. If the validation fails then you set e.Cancel to True and the user will be unable to leave that cell until they fix the data.
 
Back
Top