Attempts to put the grid into a state where editing is allowed.
[Visual Basic] Overridable Public Function BeginEdit( _ ByVal gridColumn As DataGridColumn, _ ByVal rowNumber As Integer _ ) As Boolean [C#] public virtual bool BeginEdit( DataGridColumn gridColumn, int rowNumber ); [C++] public: virtual bool BeginEdit( DataGridColumn* gridColumn, int rowNumber ); [JScript] public function BeginEdit( gridColumn : DataGridColumn, rowNumber : int ) : Boolean;
true if the method is successful; otherwise, false.
The following example uses the BeginEdit method to test if editing is possible before editing a specified column and row.
[Visual Basic]
Private Sub EditGrid() ' Get the selected row and column through the CurrentCell. Dim colNum As Long Dim rowNum As Long colNum = DataGrid1.CurrentCell.ColumnNumber rowNum = DataGrid1.CurrentCell.RowNumber ' Get the selected DataGridColumn. Dim dgCol As DataGridColumn Set dgCol = DataGrid1.GridColumns(colNum) ' Invoke the BeginEdit method to see if editing can begin. If DataGrid1.BeginEdit(dgCol, rowNum) Then ' Edit row value. Begin by getting selected row. Dim myRow As DataRow Set myRow = dgCol.DataGridTable.DataTable.Rows(rowNum) ' Invoke the Row object's BeginEdit method. myrow.BeginEdit myRow(colNum) = "New Value" ' You must accept changes on both DataRow and DataTable. myRow.AcceptChanges DataGrid1.CurrentGridTable.DataTable.AcceptChanges DataGrid1.EndEdit dgcol, rowNum, False Else Console.WriteLine("BeginEdit failed") End If End Sub
DataGrid Class | DataGrid Members | System.WinForms Namespace | EndEdit