当我在DataGridView1.Columns(6)的单元格中输入值时,如果DataGridView1.Columns(7)的单元格值大于DataGridView1.Columns的单元格值,我有一个想要检查的数据网格(6)加上一个函数的结果,该函数的参数为DataGridView1.Columns(1),并从DataGridView1.Columns(6)中获取先前插入值的总和。
我不知道的事情:
功能是:
Public Shared Function getproddeclarata(ByVal nrfpo As String) As Integer
Dim total As Integer
Dim con As New SqlConnection
Try
con = New SqlConnection("Data Source=SVNAV;Initial Catalog=NAV_Vermorel_Live;User ID=sa;Password=1234")
Using cmd As SqlCommand = New SqlCommand("SELECT cast(SUM([Productie Declarata]) as Decimal(18,2)) as TotalOreDeclarate FROM [SC Vermorel SRL$ProductieZilnica] WHERE FPO = @nrfpo", con)
cmd.Parameters.AddWithValue("@nrfpo", nrfpo)
con.Open()
total = Convert.ToInt32(cmd.ExecuteScalar())
con.Close()
End Using
Catch ex As Exception
Console.WriteLine(ex.Message)
Finally
If con IsNot Nothing Then
If con.State = ConnectionState.Open Then '
con.Close()
End If
con.Dispose()
End If
End Try
Return total
End Function
答案 0 :(得分:0)
为此,您可以将活动DataGridView1_CellEndEdit
视为:
Private Sub DataGridView1_CellEndEdit(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
Try
Dim rw As DataGridView = DirectCast(sender, DataGridView)
If e.ColumnIndex = 6 Then
If IsNumeric (rw(e.ColumnIndex, e.RowIndex).Value) andalso rw(e.ColumnIndex, e.RowIndex).Value)>0 Then
If rw(7, e.RowIndex).Value > rw(e.ColumnIndex, e.RowIndex).Value + getproddeclarata(rw(1, e.RowIndex).Value.ToString()) Then
'Same code here
End If
End If
End If
Catch ex As Exception
End Try
End Sub