DataGridTextBoxColumn.Edit Método

Definición

Prepara una celda para que pueda editarse.

C#
protected internal override void Edit(System.Windows.Forms.CurrencyManager source, int rowNum, System.Drawing.Rectangle bounds, bool readOnly, string instantText, bool cellIsVisible);
C#
protected internal override void Edit(System.Windows.Forms.CurrencyManager source, int rowNum, System.Drawing.Rectangle bounds, bool readOnly, string displayText, bool cellIsVisible);

Parámetros

source
CurrencyManager

CurrencyManager del control DataGrid al que pertenece la columna.

rowNum
Int32

Número de la fila que se está editando en esta columna.

bounds
Rectangle

Rectangledelimitador donde se va a situar el control.

readOnly
Boolean

Valor que indica si la columna es de solo lectura. Es true si el valor es de solo lectura; en caso contrario, es false.

instantTextdisplayText
String

Texto que se va a mostrar en el control.

cellIsVisible
Boolean

Valor que indica si la celda está visible. Es true si la celda está visible; en caso contrario, es false.

Ejemplos

En el ejemplo siguiente se usa el Edit método para cambiar el texto de una celda en la que se hace clic en el DataGrid control .

C#
public class Form1: Form
{
protected DataGrid dataGrid1;
protected DataSet myDataSet;

private void dataGrid1_MouseDown(object sender, MouseEventArgs e)
{
    // Use the HitTest method to get a HitTestInfo object.
    DataGrid.HitTestInfo hi;   
    DataGrid grid = (DataGrid)sender;
    hi=grid.HitTest(e.X, e.Y);
    // Test if the clicked area was a cell.
    if (hi.Type == DataGrid.HitTestType.Cell)
    {
       // If it's a cell, get the GridTable and CurrencyManager of the
       // clicked table.         
       DataGridTableStyle dgt = dataGrid1.TableStyles[0];     
       CurrencyManager cm = (CurrencyManager)
        this.BindingContext[myDataSet.Tables[dgt.MappingName]];
       // Get the Rectangle of the clicked cell.
       Rectangle cellRect = grid.GetCellBounds(hi.Row, hi.Column);
       // Get the clicked DataGridTextBoxColumn.
       MyGridColumn gridCol =
       (MyGridColumn)dgt.GridColumnStyles[hi.Column];
       // Edit the value.
       gridCol.EditCol(cm, hi.Row, cellRect, false, "New Text", true);
    }
 }
}

public class MyGridColumn:DataGridTextBoxColumn{
   public void EditCol(CurrencyManager cm, int rowNum, 
      Rectangle cellRect, bool readOnly, 
      string myString, bool isVisible){
      this.Edit(cm, rowNum, cellRect, readOnly, myString, isVisible);
   }
}

Comentarios

El Edit sitio un TextBox control de la cuadrícula en la ubicación de la celda que se está editando. El método de BeginEdit la DataGrid clase llama al método cuando una operación de edición está a punto de comenzar.

Se aplica a

Producto Versiones
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 10

Consulte también