Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Versucht, den Zustand des Datenblatts zu ändern, sodass eine Bearbeitung zulässig ist.
Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)
Syntax
'Declaration
Public Function BeginEdit ( _
gridColumn As DataGridColumnStyle, _
rowNumber As Integer _
) As Boolean
'Usage
Dim instance As DataGrid
Dim gridColumn As DataGridColumnStyle
Dim rowNumber As Integer
Dim returnValue As Boolean
returnValue = instance.BeginEdit(gridColumn, rowNumber)
public bool BeginEdit (
DataGridColumnStyle gridColumn,
int rowNumber
)
public:
virtual bool BeginEdit (
DataGridColumnStyle^ gridColumn,
int rowNumber
) sealed
public final boolean BeginEdit (
DataGridColumnStyle gridColumn,
int rowNumber
)
public final function BeginEdit (
gridColumn : DataGridColumnStyle,
rowNumber : int
) : boolean
Parameter
- gridColumn
Ein zu bearbeitender DataGridColumnStyle.
- rowNumber
Die Nummer der zu bearbeitenden Zeile.
Rückgabewert
true, wenn die Methode ordnungsgemäß funktioniert, andernfalls false.
Hinweise
Das Datenblatt weist Bearbeitungsanforderungen zurück, wenn der Benutzer bereits begonnen hat, einen Wert in eine Zelle einzugeben. In diesem Fall gibt die BeginEdit-Methode false zurück.
Beispiel
Im folgenden Codebeispiel wird die BeginEdit-Methode verwendet, um vor dem Ändern einer angegebenen Spalte und Zeile zu testen, ob eine Bearbeitung möglich ist.
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 'EditGrid
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 void EditGrid(DataGrid myGrid)
{
// Get the selected row and column through the CurrentCell.
int colNum;
int rowNum;
colNum = dataGrid1.get_CurrentCell().get_ColumnNumber();
rowNum = dataGrid1.get_CurrentCell().get_RowNumber();
// Get the selected DataGridColumnStyle.
DataGridColumnStyle dgCol;
dgCol = dataGrid1.get_TableStyles().get_Item(0).get_GridColumnStyles().
get_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 = (DataTable)(dataGrid1.get_DataSource());
myRow = myTable.get_Rows().get_Item(rowNum);
// Invoke the Row object's BeginEdit method.
myRow.BeginEdit();
myRow.set_Item(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");
}
} //EditGrid
Plattformen
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
Siehe auch
Referenz
DataGrid-Klasse
DataGrid-Member
System.Windows.Forms-Namespace
EndEdit