vb.net 如何手动触发 Datagridview.cellValidating?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18915735/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to Trigger Datagridview.cellValidating manually?
提问by Saurabh
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.
我正在从另一个表中在我的 Datagridview 中插入几条记录,我想为我插入的每条记录调用 CellValidating 事件。请帮帮我。
Here is my 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 is the name of grid, m_BindingsrcDetail is datasource for grdDetails
grddetails 是网格的名称,m_BindingsrcDetail 是 grdDetails 的数据源
According to This, You should be able to force the validation trigger using BeginEdit and EndEdit. but its not happening.
根据This,您应该能够使用 BeginEdit 和 EndEdit 强制验证触发器。但它没有发生。
I am fetching Product description, MRP and other details in cell validating. So it necessary to call it.
我正在单元验证中获取产品描述、MRP 和其他详细信息。所以有必要调用它。
回答by Justin Russo
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;

