次の方法で共有


DataGridColumnStyle.Edit メソッド (CurrencyManager, Int32, Rectangle, Boolean, String)

指定した CurrencyManager 、行番号、および Rectangle パラメータを使用して、編集するためにセルを準備します。

Overloads Protected Friend Overridable Sub Edit( _
   ByVal source As CurrencyManager, _   ByVal rowNum As Integer, _   ByVal bounds As Rectangle, _   ByVal readOnly As Boolean, _   ByVal instantText As String _)
[C#]
protected internal virtual void Edit(CurrencyManagersource,introwNum,Rectanglebounds,boolreadOnly,stringinstantText);
[C++]
protected public: virtual void Edit(CurrencyManager* source,introwNum,Rectanglebounds,boolreadOnly,String* instantText);
[JScript]
protected internal function Edit(
   source : CurrencyManager,rowNum : int,bounds : Rectangle,readOnly : Boolean,instantText : String);

パラメータ

  • source
    DataGridColumnStyleCurrencyManager
  • rowNum
    編集されている列の行番号。
  • bounds
    コントロールの配置先の Rectangle
  • readOnly
    列が読み取り専用かどうかを示す値。値が読み取り専用の場合は true 。それ以外の場合は false
  • instantText
    コントロール内で表示するテキスト。

解説

通常、 Edit メソッドは、編集されるセルの場所のグリッドにコントロールを配置します。

使用例

[Visual Basic, C#, C++] Edit メソッドを使用して、 System.Windows.Forms.DataGrid コントロール上でクリックされたセルのテキストを変更する例を次に示します。

 
Public Class Form1
   Inherits Form

   Protected myDataSet As DataSet

   Shared Sub Main()
   End Sub
    
   Protected Sub dataGrid1_MouseDown(sender As Object, e As MouseEventArgs)
      ' Use the HitTest method to get a HitTestInfo object.
      Dim hi As System.Windows.Forms.DataGrid.HitTestInfo
      Dim grid As DataGrid = CType(sender, DataGrid)
      hi = grid.HitTest(e.X, e.Y)
      ' Test if the clicked area was a cell.
      If hi.Type = DataGrid.HitTestType.Cell Then
         ' If it's a cell, get the GridTable and CurrencyManager of the
         ' clicked table.         
         Dim dgt As DataGridTableStyle = grid.TableStyles(0)
         Dim myCurrencyManager As CurrencyManager = _
         CType(Me.BindingContext _
         (myDataSet.Tables(dgt.MappingName)), CurrencyManager)
         ' Get the Rectangle of the clicked cell.
         Dim cellRect As Rectangle
         cellRect = grid.GetCellBounds(hi.Row, hi.Column)
         ' Get the clicked DataGridTextBoxColumn.
         Dim gridCol As MyColumnStyle= CType(dgt.GridColumnStyles _
         (hi.Column), MyColumnStyle)
         ' Edit the value.
         gridCol.EditVal(myCurrencyManager, hi.Row, cellRect, False, "New Text")
      End If
   End Sub 
End Class 

Public Class MyColumnStyle
   Inherits DataGridTextBoxColumn
   Public Sub EditVal(cm As CurrencyManager, row As Integer, _
   rec As Rectangle, bReadOnly As Boolean, text As String)
      MyBase.Edit(cm, row, rec, bReadOnly, text)
   End Sub
End Class

[C#] 
public class Form1: Form
{
static void Main(){}

protected DataSet myDataSet;

protected 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)
           this.BindingContext[myDataSet.Tables[dgt.MappingName]];
       // Get the Rectangle of the clicked cell.
       Rectangle cellRect;
       cellRect=grid.GetCellBounds(hi.Row, hi.Column);
       // Get the clicked DataGridTextBoxColumn.
       MyColumnStyle gridCol =(MyColumnStyle) 
       dgt.GridColumnStyles[hi.Column];
       // 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);
    }
}
}

[C++] 
public __gc class Form1: public Form
{
protected:
   DataSet* myDataSet;

   void dataGrid1_MouseDown(Object* sender, MouseEventArgs* e)
   {
      // Use the HitTest method to get a HitTestInfo object.
      System::Windows::Forms::DataGrid::HitTestInfo* hi;   
      DataGrid* grid = dynamic_cast<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->Item[0];     
         CurrencyManager* myCurrencyManager =
            dynamic_cast<CurrencyManager*>(this->BindingContext->Item[myDataSet->Tables->Item[dgt->MappingName]]);
         // Get the Rectangle of the clicked cell.
         Rectangle cellRect;
         cellRect=grid->GetCellBounds(hi->Row, hi->Column);
         // Get the clicked DataGridTextBoxColumn.
         MyColumnStyle* gridCol =dynamic_cast<MyColumnStyle*>(dgt->GridColumnStyles->Item[hi->Column]);
         // Edit the value.
         gridCol->EditVal(myCurrencyManager, hi->Row, cellRect, false, S"New Text");
      }
   }

public:
   __gc class MyColumnStyle:public DataGridTextBoxColumn{
   public:
      void EditVal(CurrencyManager* cm, int row, Rectangle rec, bool readOnly, String* text){
         this->Edit(cm, row, rec, readOnly, text);
      }
   };
};

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

DataGridColumnStyle クラス | DataGridColumnStyle メンバ | System.Windows.Forms 名前空間 | DataGridColumnStyle.Edit オーバーロードの一覧