DataGridColumnStyle.Edit Method (CurrencyManager, Int32, Rectangle, Boolean, String)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Prepares the cell for editing using the specified CurrencyManager, row number, and Rectangle parameters.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

protected internal virtual void Edit(
	CurrencyManager source,
	int rowNum,
	Rectangle bounds,
	bool readOnly,
	string displayText


Type: System.Windows.Forms.CurrencyManager

The CurrencyManager for the DataGridColumnStyle.

Type: System.Int32

The row number in this column which is being edited.

Type: System.Drawing.Rectangle

The Rectangle in which the control is to be sited.

Type: System.Boolean

A value indicating whether the column is a read-only. true if the value is read-only; otherwise, false.

Type: System.String

The text to display in the control.

Typically, the Edit method sites a control onto the grid at the location of the cell being edited.

The following code example uses the Edit method to change the text of a clicked cell in the System.Windows.Forms.DataGrid control.

public class Form1: Form
static void Main(){}

protected DataSet myDataSet;

private void dataGrid1_MouseDown(object sender, MouseEventArgs e)
    // Use the HitTest method to get a HitTestInfo object.
    System.Windows.Forms.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 = grid.TableStyles[0];     
       CurrencyManager myCurrencyManager = (CurrencyManager)
       // Get the Rectangle of the clicked cell.
       Rectangle cellRect;
       cellRect=grid.GetCellBounds(hi.Row, hi.Column);
       // Get the clicked DataGridTextBoxColumn.
       MyColumnStyle gridCol =(MyColumnStyle) 
       // Edit the value.
       gridCol.EditVal(myCurrencyManager, hi.Row, cellRect, false, "New Text");

public class MyColumnStyle:DataGridTextBoxColumn{
	public void EditVal(CurrencyManager cm, int row, Rectangle rec, 
	bool readOnly, string text){
		this.Edit(cm, row, rec, readOnly, text);

.NET Framework
Available since 1.1
Return to top