DataGrid.BeginEdit(DataGridColumnStyle, Int32) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Attempts to put the grid into a state where editing is allowed.
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
Parameters
- gridColumn
- DataGridColumnStyle
A DataGridColumnStyle to edit.
- rowNumber
- Int32
The number of the row to edit.
Returns
true
if the method is successful; otherwise, false
.
Implements
Examples
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->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
Remarks
The grid will deny edit requests if the user already started typing into a cell. In that case, the BeginEdit method will return false
.
Applies to
See also
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET