Reputation: 503
I have method validatingeditor to validate for duplicate
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;
}
}
}
}
}
But it says object reference not set which the problem is at DataView currentDataView = view.DataSource as DataView;
But I do not understand why.
Upvotes: 0
Views: 31
Reputation: 503
I was populating my gridcontrol with the ado entity dataset. so after calling adapter.Fill(dataset)
. I also have to write gridcontrol.DataSource=dataset;
Upvotes: 0