public virtual void BindBack(DataSet ds, string tableName) { if (this.EditItemIndex >= 0) { DataGridItem item = this.Items[this.EditItemIndex]; <----- A int CellNumber = 0; foreach(TableCell cell in item.Cells) { // Need to check HasControls because if a column is set to ReadOnly, // HasControls() returns false. Trying to process the controls collection // when HasControls() is false, throws an exception. if (cell.HasControls()) { DataGridColumn column = this.Columns[CellNumber]; if (column is BoundColumn) { BoundColumn BoundCol = (BoundColumn)column; if (cell.Controls[0] is TextBox) { TextBox txtBox = (TextBox)cell.Controls[0]; ds.Tables[tableName].Rows[EditItemIndex][BoundCol.DataField] = txtBox.Text; <---- B } } } CellNumber++; } } }