我有一个DataGridView
并通过下面的代码从我的数据库动态地填充它
DataGridViewTextBoxColumn colID = new DataGridViewTextBoxColumn();
colID.HeaderText = "id";
colID.DataPropertyName = "id";
colID.ReadOnly = true;
colID.Visible = false;
dtgvLoadEx.Columns.Add(colID);
DataGridViewTextBoxColumn colLoadExpiryDate = new DataGridViewTextBoxColumn();
//CalendarColumn colLoadExpiryDate = new CalendarColumn();
colLoadExpiryDate.HeaderText = "LoadExpiryDate(mm/dd/yy)";
colLoadExpiryDate.Width = 158;
colLoadExpiryDate.DataPropertyName = "LoadExpiryDate";
colLoadExpiryDate.ReadOnly = false;
colLoadExpiryDate.MaxInputLength = 10;
dtgvLoadEx.Columns.Add(colLoadExpiryDate);
dtgvLoadEx.DataSource = data(); //Return data table from my Database
如你所见,我有一个
Date
专栏。当我试图编辑该列的单元格并键入无效格式时,将触发DataError
事件。现在我只想从
private void dtgvLoadEx_DataError(object sender, DataGridViewDataErrorEventArgs e) {
}
或任何其他进程以获取错误文本。
最佳答案
好吧,伙计们,我已经解决了这个问题。我来分享
private void dtgvLoadEx_DataError(object sender, DataGridViewDataErrorEventArgs e)
{
string s = dtgvLoadEx.EditingControl.Text;
}