Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

DataGrid.BeginEdit Method

Attempts to put the grid into a state where editing is allowed.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
public bool BeginEdit(
	DataGridColumnStyle gridColumn,
	int rowNumber


Type: System.Windows.Forms.DataGridColumnStyle

A DataGridColumnStyle to edit.

Type: System.Int32

The number of the row to edit.

Return Value

Type: System.Boolean
true if the method is successful; otherwise, false.


IDataGridEditingService.BeginEdit(DataGridColumnStyle, Int32)

The grid will deny edit requests if the user already started typing into a cell. In that case, the BeginEdit method will return false.

The following code example uses the BeginEdit method to test if editing is possible before changing a specified column and row.

private void EditGrid(DataGrid dataGrid1){
    // Get the selected row and column through the CurrentCell. 
    int colNum;
    int rowNum;
    colNum = dataGrid1.CurrentCell.ColumnNumber;
    rowNum = dataGrid1.CurrentCell.RowNumber;
    // Get the selected DataGridColumnStyle.
    DataGridColumnStyle dgCol;
    dgCol = dataGrid1.TableStyles[0].GridColumnStyles[colNum];
    // Invoke the BeginEdit method to see if editing can begin. 
    if (dataGrid1.BeginEdit(dgCol, rowNum)){
       // Edit row value. Get the DataTable and selected row.
       DataTable myTable;
       DataRow myRow;
       // Assuming the DataGrid is bound to a DataTable.
       myTable = (DataTable) dataGrid1.DataSource;
       myRow = myTable.Rows[rowNum];
       // Invoke the Row object's BeginEdit method.
       myRow[colNum] = "New Value";
       // You must accept changes on both DataRow and DataTable.
       dataGrid1.EndEdit(dgCol, rowNum, false);
      Console.WriteLine("BeginEdit failed");

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft. All rights reserved.