次の方法で共有


DataGrid.BeginEdit メソッド

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

Public Overridable Function BeginEdit( _
   ByVal gridColumn As DataGridColumnStyle, _   ByVal rowNumber As Integer _) As Boolean Implements IDataGridEditingService.BeginEdit
[C#]
public virtual bool BeginEdit(DataGridColumnStylegridColumn,introwNumber);
[C++]
public: virtual bool BeginEdit(DataGridColumnStyle* gridColumn,introwNumber);
[JScript]
public function BeginEdit(
   gridColumn : DataGridColumnStyle,rowNumber : int) : Boolean;

パラメータ

戻り値

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

実装

IDataGridEditingService.BeginEdit

解説

ユーザーがセルにキー入力を開始していた場合は、グリッドで編集要求が拒否されます。この場合、 BeginEdit メソッドは false を返します。

使用例

[Visual Basic, C#, C++] BeginEdit メソッドを使用して、指定した列と行を編集する前に編集できるかどうかをテストする例を次に示します。

 
Private Sub EditGrid(myGrid 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 'EditGrid

[C#] 
private void EditGrid(DataGrid myGrid){
    // 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");
    }
 }
 

[C++] 
private:
void EditGrid(DataGrid* /*myGrid*/){
    // 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->Item[0]->GridColumnStyles->Item[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 = dynamic_cast<DataTable*> (dataGrid1->DataSource);
       myRow = myTable->Rows->Item[rowNum];
       // Invoke the Row object's BeginEdit method.
       myRow->BeginEdit();
       myRow->Item[colNum] = S"New Value";
       // You must accept changes on both DataRow and DataTable.
       myRow->AcceptChanges();
       myTable->AcceptChanges();
       dataGrid1->EndEdit(dgCol, rowNum, false);
    }
    else{
      Console::WriteLine(S"BeginEdit failed");
    }
}
 

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

DataGrid クラス | DataGrid メンバ | System.Windows.Forms 名前空間 | EndEdit