Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
There is a datagridview where there is PresentLinkedQty column and PendingToLink column.The PendingToLink column is noneditable whereas PresentLinkedQty column is editable.When the user will edit PresentLinkedQty should not be greater than PendingToLinkQty.
I am checking the input in PresentLinkedQty and checking if it is greater than PendingToLink in cellvalidating event and setting the error text.Error text is not getting displayed if after setting the error text i am putting e.cancel=true.

If I am not putting e.cancel=true then error text is displayed but after the user selects another cell the error text goes away.

What i want to achieve is after validating the input i will show the error text accrordingly and also the focus should not leave that cell if the user has put wrong input.

Below is the code snippet-
VB
Private Sub DataGridView1_CellValidating(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles DataGridView1.CellValidating
        Dim index As Integer = e.RowIndex
        If e.FormattedValue > CType(DataGridView1.Rows(index).Cells("PendingToLink").Value, Double) Then
            MessageBox.Show("Linked Qty must not be greater than pending to link")
            DataGridView1.CurrentRow.Cells("PresentLinkedQty").ErrorText = "Linked Qty must not be greater than pending to link"
            e.Cancel = True
        Else
            If Not DataGridView1.CurrentRow.Cells("PresentLinkedQty").ErrorText Is Nothing Then
                DataGridView1.CurrentRow.Cells("PresentLinkedQty").ErrorText = String.Empty
            End If
        End If
    End Sub
Posted
Updated 11-Oct-11 19:26pm
v3
Comments
Marc A. Brown 11-Oct-11 14:59pm    
Please provide us with the code snippet that is causing the problem.

1 solution

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