编辑datagridviewcell时发生提交错误 [英] Commit Error occurs while editing datagridviewcell
问题描述
我有一个datagrid视图,该视图从MS ACCESS数据库中检索数据.列之一是日期/时间类型.我使用以下代码在datagridview中检索此列
I have a datagrid view which retrieve data from MS ACCESS database.and one of the column is Date/Time type. i retrieve this column in datagridview using the following code
dataGridView1.Columns["DATERECEIVED"].DefaultCellStyle.Format = "yyyy-MM-dd HH:mm:ss";
我也使用以下事件处理程序
I use the following eventhandler too
private void dataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs anError)
{
if (anError.Exception != null && anError.Context == DataGridViewDataErrorContexts.Commit)
{
MessageBox.Show("Error : " + anError.Context.ToString());
anError.Cancel = true;
}
}
问题是,每当我在DATERECEIVED列的单元格中键入或尝试键入第一位数字时,它都会引发Dataerror事件并显示错误消息:Commit.当我单击messageBox按钮确定时,它使我可以继续进行进一步的编辑.我如何摆脱这个问题.请有人帮我
the problem is that whenever I type or attempt to type first digit in the cell of the column DATERECEIVED it raise the Dataerror event and shows the message Error:Commit. when I click the messageBox button OK it allows me to continue further editing. how I can get rid of this problem. please somebody help me
推荐答案
您可以引发"dataGridView1_CellEndEdit"事件,然后使用IsDate检查输入的日期是否有效.
You could raise a ''dataGridView1_CellEndEdit'' event, and then check, using IsDate, if the date entered is valid.
这篇关于编辑datagridviewcell时发生提交错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!