vs2005中的datagridView控件的dataError事件怎么触发呢?(200分)

  • 主题发起人 chinaceleron
  • 开始时间
C

chinaceleron

Unregistered / Unconfirmed
GUEST, unregistred user!
各位老大
新的vs2005中,有个新的datagridview控件
有一个DataError事件,这个事件是怎么触发的呢
我想实现下面的功能
我在和datagridview连接的dataset中,先关掉了约束,然后增加行

this.dataSet11.EnforceConstraints = false;
DataRow row = this.dataSet11.CodeDevelopZone.NewRow();
//this.SetGuidValue(row);
this.dataSet11.CodeDevelopZone.Rows.Add(row);
再在提交的时候打开约束
try
{
this.dataSet11.EnforceConstraints = true;
this.codeDevelopZoneTableAdapter1.Update(this.dataSet11);
}
catch(Exception ex)
{
}
我发现,如果使用的try。。。catch块
datagridview的相应的cell中会出现红色的感叹号错误标记,但他的内容是系统提供的
我想把ErrorText内容换成是中文的,所以,就写了下面的dataGridview的DataError事件
但是,我发现,DataError事件是不会被触发的,请问DataError事件怎样才能触发呢?
我已经把DataError事件作了事件委托了
private void dataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs e)
{
DataGridView view = (DataGridView)sender;
view.Rows[e.RowIndex].ErrorText = "an error";
view.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = "an error";
e.ThrowException = true;
}
 

Similar threads

顶部