編集するためにセルを準備します。
Overloads Protected Friend Overridable Sub Edit( _
ByVal source As CurrencyManager, _ ByVal rowNum As Integer, _ ByVal bounds As Rectangle, _ ByVal readOnly As Boolean _)
[C#]
protected internal virtual void Edit(CurrencyManagersource,introwNum,Rectanglebounds,boolreadOnly);
[C++]
protected public: virtual void Edit(CurrencyManager* source,introwNum,Rectanglebounds,boolreadOnly);
[JScript]
protected internal function Edit(
source : CurrencyManager,rowNum : int,bounds : Rectangle,readOnly : Boolean);
パラメータ
- source
DataGridColumnStyle の CurrencyManager 。 - rowNum
編集対象の行番号。 - bounds
コントロールの配置先の外接する Rectangle 。 - readOnly
列が読み取り専用かどうかを示す値。値が読み取り専用の場合は true 。それ以外の場合は false 。
解説
通常、 Edit メソッドは、編集されるセルの場所のグリッドにコントロールを配置します。
使用例
[Visual Basic, C#, C++] Edit メソッドを使用して、 System.Windows.Forms.DataGrid コントロール上でクリックされたセルのテキストを変更する例を次に示します。
Public Class Form1
Inherits Form
Protected dataGrid1 As DataGrid
Protected myDataSet As DataSet
Shared Sub Main()
End Sub
Protected Sub dataGrid1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs)
' Use the HitTest method to get a HitTestInfo object.
Dim hi As 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 = System.Windows.Forms.DataGrid.HitTestType.Cell Then
' If it's a cell, get the GridTable and CurrencyManager of the
' clicked table.
Dim dgt As DataGridTableStyle = dataGrid1.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.EditValue(myCurrencyManager, hi.Row, cellRect, False)
End If
End Sub
End Class
Public Class MyColumnStyle
Inherits DataGridTextBoxColumn
Public Sub EditValue(cm As CurrencyManager, row As Integer, _
rec As Rectangle, bReadOnly As Boolean)
MyBase.Edit(cm, row, rec, bReadOnly)
End Sub
End Class
[C#]
public class Form1: Form
{
protected DataGrid dataGrid1;
protected DataSet myDataSet;
static void Main(){}
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 ) return;
// If it's a cell, get the GridTable and CurrencyManager of the
// clicked table.
DataGridTableStyle dgt = dataGrid1.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.EditValue(myCurrencyManager, hi.Row, cellRect,false);
}
}
public class MyColumnStyle:DataGridTextBoxColumn{
public void EditValue(CurrencyManager cm, int row, Rectangle rec,
bool ReadOnly){
this.Edit(cm, row, rec, ReadOnly);
}
}
[C++]
public __gc class MyColumnStyle:public DataGridTextBoxColumn{
public:
void EditValue(CurrencyManager* cm, int row, Rectangle rec, bool ReadOnly){
this->Edit(cm, row, rec, ReadOnly);
}
};
public __gc class Form1: public Form
{
protected:
DataGrid* dataGrid1;
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 ) return;
// If it's a cell, get the GridTable and CurrencyManager of the
// clicked table.
DataGridTableStyle* dgt = dataGrid1->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->EditValue(myCurrencyManager, hi->Row, cellRect,false);
}
};
[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 オーバーロードの一覧