如何手动触发Datagridview.cellValidating? [英] How to Trigger Datagridview.cellValidating manually?
问题描述
我从另一个表我的DataGridView中插入一些记录,我想打电话给CellValidating事件,每一条记录我插入。请帮我。
I am inserting few records in my Datagridview from another table, I want to call CellValidating event for every record I insert. Please help me out.
下面是我的code
m_Sqlstr = "Select Distinct RFID, Prod_Code, Lot_No From ScanStk Where BatchNo = '" & strBatchno & "' "
m_SqlCmd = New SqlCommand(m_Sqlstr, Con)
Con.Open()
RFIDReader = m_SqlCmd.ExecuteReader(CommandBehavior.CloseConnection)
With m_BindingsrcDetail
While RFIDReader.Read
.AddNew()
.Current("SR") = m_BindingsrcDetail.Count
.Current("LOT_NO") = RFIDReader("LOT_NO").ToString.Trim
.Current("PROD_CODE") = RFIDReader("PROD_CODE").ToString
.Current("QUANTITY") = 1
GrdDetails.BeginEdit(False)
GrdDetails.CurrentRow.Cells("Prod_code").Value = RFIDReader("PROD_CODE").ToString
GrdDetails.EndEdit()
End While
End With
grddetails是网格的名称, m_BindingsrcDetail是数据源grdDetails
grddetails is the name of grid, m_BindingsrcDetail is datasource for grdDetails
据<一href="http://stackoverflow.com/questions/14529757/validate-datagridview-cells-for-data-read-from-file/14530181#14530181">This ,你应该能够强制使用BeginEdit和EndEdit中验证触发。但它不会发生。
According to This , You should be able to force the validation trigger using BeginEdit and EndEdit. but its not happening.
我取产品说明,MRP和细胞确证其他细节。因此,有必要调用它。
I am fetching Product description, MRP and other details in cell validating. So it necessary to call it.
推荐答案
您必须改变当前单元格,然后回去吧。试试这个。您可能必须改变它,因为它没有经过测试。
You have to change the current cell and then go back to it. Give this a try. You may have to alter it, as it hasn't been tested.
BeginEdit();
DataGridViewCell currentCell = GrdDetails.CurrentRow.Cells("Prod_code");
EndEdit();
CurrentCell = null;
CurrentCell = currentCell;
这篇关于如何手动触发Datagridview.cellValidating?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!