How to edit specific field value,only if another field value is changed?

112 views Asked by At

I have WinForm aplication,.Net framework 4.5 with vs2012 and Sqlserver 2008 R2.

In my form i use "BindingSource_CurrentItemChanged" to add new value if row.IsNew (user insert a new row)

 DataRowView row = (DataRowView) this.BindingSource.Current;
 //if row is null then exit form method.
 if(row==null)
    return;
 if(row.IsNew)
    {
      row["CreatedUserID"] = this.UserID;
      row["ModifiedUserID"] = this.UserID;
    }  

This worked successfully.

Then i want to write a method that when user edit a desire field value, my code put "UserID" to ModifiedUserID automatically (some thing like this):

  ... row["ModifiedUserID"] = this.UserID;

I used below code in BindongSource_ListChanged but get error:

if (e.ListChangedType == ListChangedType.ItemChanged)
        {
            DataRowView row = (DataRowView)this.ApplicationFilesBindingSource.Current;
            if (row == null)
                return;
            row["ModifiedUserID"] = this.ID;
        }

Error: DataTable Internal Index is corrupted: '5'.

after this if write a code in BindingSource_CurrentItemChanged

  if (row.Row.RowState == DataRowState.Modified)
            row["ModifiedUserID"] = User.User.Current.ID;

this code also raise a same exception too:

Error: DataTable Internal Index is corrupted: '5'.

Where do i put this code for change "ModifiedUserID" to this.UserID? in which event of BindingSource or DataGridView ?

0

There are 0 answers