我有方法验证编辑器来验证重复
private void GridView1_ValidatingEditor(object sender, DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventArgs e)
{
GridView view = sender as GridView;
DataView currentDataView = view.DataSource as DataView;
if (view.FocusedColumn.FieldName == "Sequence")
{
//check duplicate code
string currentCode = e.Value.ToString();
for (int i = 0; i < currentDataView.Count; i++)
{
if (i != view.GetDataSourceRowIndex(view.FocusedRowHandle))
{
if (currentDataView[i]["Sequence"].ToString() == currentCode)
{
e.ErrorText = "Duplicate Code detected.";
e.Valid = false;
break;
}
}
}
}
}
但它说对象引用未设置问题出在DataView currentDataView = view.DataSource as DataView;
但我不明白为什么。