DataGrid.BeginEdit(DataGridColumnStyle, Int32) メソッド

定義

グリッドが編集できる状態に移行するよう試みます。

public:
 virtual bool BeginEdit(System::Windows::Forms::DataGridColumnStyle ^ gridColumn, int rowNumber);
public bool BeginEdit (System.Windows.Forms.DataGridColumnStyle gridColumn, int rowNumber);
abstract member BeginEdit : System.Windows.Forms.DataGridColumnStyle * int -> bool
override this.BeginEdit : System.Windows.Forms.DataGridColumnStyle * int -> bool
Public Function BeginEdit (gridColumn As DataGridColumnStyle, rowNumber As Integer) As Boolean

パラメーター

gridColumn
DataGridColumnStyle

編集する DataGridColumnStyle

rowNumber
Int32

編集する行の番号。

戻り値

Boolean

このメソッドが成功した場合は true。それ以外の場合は false

実装

次のコード例では、このメソッドを BeginEdit 使用して、指定した列と行を変更する前に編集が可能かどうかをテストします。

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->BeginEdit();
         myRow[ colNum ] = "New Value";
         // You must accept changes on both DataRow and DataTable.
         myRow->AcceptChanges();
         myTable->AcceptChanges();
         dataGrid1->EndEdit( dgCol, rowNum, false );
      }
      else
      {
         Console::WriteLine( "BeginEdit failed" );
      }
   }
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.BeginEdit();
       myRow[colNum] = "New Value";
       // You must accept changes on both DataRow and DataTable.
       myRow.AcceptChanges();
       myTable.AcceptChanges();
       dataGrid1.EndEdit(dgCol, rowNum, false);
    }
    else{
      Console.WriteLine("BeginEdit failed");
    }
 }
Private Sub EditGrid(dataGrid1 As DataGrid)
    ' Get the selected row and column through the CurrentCell.
    Dim colNum As Integer
    Dim rowNum As Integer
    colNum = dataGrid1.CurrentCell.ColumnNumber
    rowNum = dataGrid1.CurrentCell.RowNumber
    ' Get the selected DataGridColumnStyle.
    Dim dgCol As DataGridColumnStyle
    dgCol = dataGrid1.TableStyles(0).GridColumnStyles(colNum)
    ' Invoke the BeginEdit method to see if editing can begin.
    If dataGrid1.BeginEdit(dgCol, rowNum) Then
        ' Edit row value. Get the DataTable and selected row.
        Dim myTable As DataTable
        Dim myRow As DataRow
        ' Assuming the DataGrid is bound to a DataTable.
        myTable = CType(dataGrid1.DataSource, DataTable)
        myRow = myTable.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()
        myTable.AcceptChanges()
        dataGrid1.EndEdit(dgCol, rowNum, False)
    Else
        Console.WriteLine("BeginEdit failed")
    End If
End Sub

注釈

ユーザーが既にセルへの入力を開始した場合、グリッドは編集要求を拒否します。 その場合、メソッドは BeginEdit .false

適用対象

こちらもご覧ください