0
我正在創建一個Form
,其中包含Bound Datagridview
。在完成輸入後強制datagridview調用行驗證
Private Sub PurchaseInRowAdd()
'add new row to datagridview
Dim dtRow As DataRow = CType(Me.dgvPurchaseIn.DataSource, DataTable).NewRow()
dtRow.Item("InvoiceID") = 0
dtRow.Item("KindID") = CType(CType(Me.dgvPurchaseIn.Columns("colPurchaseKind"), DataGridViewComboBoxColumn).DataSource, DataTable).Rows(0)("KindID")
dtRow.Item("InvoiceSign") = ""
dtRow.Item("InvoiceNo") = ""
dtRow.Item("InvoiceDate") = New Date(objController.ProcessYear, objController.ProcessMonth, 1)
dtRow.Item("ID") = CType(CType(Me.dgvPurchaseIn.Columns("colPurchaseCustomer"), DataGridViewComboBoxColumn).DataSource, DataTable).Rows(0)("ID")
dtRow.Item("Product") = ""
dtRow.Item("Price") = "0.00"
dtRow.Item("Note") = ""
dtRow.Item("Tax") = CType(CType(Me.dgvPurchaseIn.Columns("colPurchaseKind"), DataGridViewComboBoxColumn).DataSource, DataTable).Rows(0)("Tax")
dtRow.Item("TaxCode") = CType(CType(Me.dgvPurchaseIn.Columns("colPurchaseCustomer"), DataGridViewComboBoxColumn).DataSource, DataTable).Rows(0)("TaxCode")
dtRow.Item("VAT") = ""
CType(Me.dgvPurchaseIn.DataSource, DataTable).Rows.Add(dtRow)
End Sub
這裏的問題是,當用戶新行,然後按在完成輸入輸入,Row_Validating
還沒有被解僱,因爲它下面沒有行:在或Row_Validating
,我通過添加新行Datagridview
。那麼當用戶輸入完成並按下回車鍵後,如何強制Row_Validating
觸發?
我找到了this解決方案,但它不適合我的情況,因爲我不想將Enable Adding
設置爲True
。我想通過代碼來處理行添加。