Export (0) Print
Expand All

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

This member overrides DataGridColumnStyle.Edit(CurrencyManager, Int32, Rectangle, Boolean, String, Boolean), and more complete documentation might be available in that topic.

Prepares a cell for editing.

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

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

Parameters

source
Type: System.Windows.Forms.CurrencyManager

The CurrencyManager of the DataGrid control the column belongs to.

rowNum
Type: System.Int32

The row number in this column being edited.

bounds
Type: System.Drawing.Rectangle

The bounding Rectangle in which the control is to be sited.

readOnly
Type: System.Boolean

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

displayText
Type: System.String

The text to display in the control.

cellIsVisible
Type: System.Boolean

A value indicating whether the cell is visible. true if the cell is visible; otherwise, false.

The Edit sites a TextBox control on the grid at the location of the cell being edited. The method is called by the DataGrid class's BeginEdit method when an editing operation is about to begin.

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

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);
   }
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft