/// <summary> /// Check if the specified row is the active row (focused), return false if it is not the active row. Then call the BeginEdit on the associated DataRowView. Add a row to the DataView if required. Returns true if the method sucesfully call the BeginEdit and set the EditingRow property. /// </summary> /// <param name="gridRow"></param> /// <returns></returns> public bool BeginEditRow(int gridRow) { // if (Selection.ActivePosition.IsEmpty() || Selection.ActivePosition.Row != gridRow) // return false; if (gridRow != EditingRow) { EndEditingRow(false); //Terminate the old edit if present System.Data.DataRowView newEditingRow = null; if (DataSource != null) { int dataIndex = Rows.IndexToDataSourceIndex(gridRow); if (dataIndex == DataSource.Count && DataSource.AllowNew) //Last Row { DataSource.AddNew(); newEditingRow = DataSource[dataIndex]; } else if (dataIndex < DataSource.Count) { newEditingRow = DataSource[dataIndex]; } } if (newEditingRow != null) { mEditingInfo = new EditingInfo(newEditingRow, gridRow); EditingDataRow.BeginEdit(); } } return(true); }
/// <summary> /// Calls the CancelEdit or the EndEdit on the editing Row and set to null the editing row. /// </summary> /// <param name="cancel"></param> public void EndEditingRow(bool cancel) { if (EditingDataRow != null) { if (cancel) { EditingDataRow.CancelEdit(); } //These lines can throw an error if the row is not valid EditingDataRow.EndEdit(); mEditingInfo = new EditingInfo(null, -1); } }