DataGridViewCell.InitializeEditingControl 메서드

정의

셀을 편집하는 데 사용되는 컨트롤을 초기화합니다.

public:
 virtual void InitializeEditingControl(int rowIndex, System::Object ^ initialFormattedValue, System::Windows::Forms::DataGridViewCellStyle ^ dataGridViewCellStyle);
public virtual void InitializeEditingControl (int rowIndex, object initialFormattedValue, System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle);
abstract member InitializeEditingControl : int * obj * System.Windows.Forms.DataGridViewCellStyle -> unit
override this.InitializeEditingControl : int * obj * System.Windows.Forms.DataGridViewCellStyle -> unit
Public Overridable Sub InitializeEditingControl (rowIndex As Integer, initialFormattedValue As Object, dataGridViewCellStyle As DataGridViewCellStyle)

매개 변수

rowIndex
Int32

셀 위치의 행 인덱스(0부터 시작)입니다.

initialFormattedValue
Object

편집이 시작될 때 셀에 표시되는 값을 나타내는 Object입니다.

dataGridViewCellStyle
DataGridViewCellStyle

셀의 스타일을 나타내는 DataGridViewCellStyle입니다.

예외

연결된 DataGridView가 없는 경우나 있더라도 연결된 편집 컨트롤이 없는 경우

예제

다음 코드 예제에서는 클래스에서 파생 되는 간단한 클래스에서 메서드를 재정 InitializeEditingControlDataGridViewTextBoxCell 하는 방법을 보여 줍니다. 이 예제는 방법: Windows Forms DataGridView 셀의 호스트 컨트롤에 제공된 더 큰 코드 예제의 일부입니다.

public class CalendarCell : DataGridViewTextBoxCell
{

    public CalendarCell()
        : base()
    {
        // Use the short date format.
        this.Style.Format = "d";
    }

    public override void InitializeEditingControl(int rowIndex, object 
        initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
    {
        // Set the value of the editing control to the current cell value.
        base.InitializeEditingControl(rowIndex, initialFormattedValue, 
            dataGridViewCellStyle);
        CalendarEditingControl ctl = 
            DataGridView.EditingControl as CalendarEditingControl;
        // Use the default row value when Value property is null.
        if (this.Value == null)
        {
            ctl.Value = (DateTime)this.DefaultNewRowValue;
        }
        else
        {
            ctl.Value = (DateTime)this.Value;
        }
    }

    public override Type EditType
    {
        get
        {
            // Return the type of the editing control that CalendarCell uses.
            return typeof(CalendarEditingControl);
        }
    }

    public override Type ValueType
    {
        get
        {
            // Return the type of the value that CalendarCell contains.
            
            return typeof(DateTime);
        }
    }

    public override object DefaultNewRowValue
    {
        get
        {
            // Use the current date and time as the default value.
            return DateTime.Now;
        }
    }
}
Public Class CalendarCell
    Inherits DataGridViewTextBoxCell

    Public Sub New()
        ' Use the short date format.
        Me.Style.Format = "d"
    End Sub

    Public Overrides Sub InitializeEditingControl(ByVal rowIndex As Integer, _
        ByVal initialFormattedValue As Object, _
        ByVal dataGridViewCellStyle As DataGridViewCellStyle)

        ' Set the value of the editing control to the current cell value.
        MyBase.InitializeEditingControl(rowIndex, initialFormattedValue, _
            dataGridViewCellStyle)

        Dim ctl As CalendarEditingControl = _
            CType(DataGridView.EditingControl, CalendarEditingControl)

        ' Use the default row value when Value property is null.
        If (Me.Value Is Nothing) Then
            ctl.Value = CType(Me.DefaultNewRowValue, DateTime)
        Else
            ctl.Value = CType(Me.Value, DateTime)
        End If
    End Sub

    Public Overrides ReadOnly Property EditType() As Type
        Get
            ' Return the type of the editing control that CalendarCell uses.
            Return GetType(CalendarEditingControl)
        End Get
    End Property

    Public Overrides ReadOnly Property ValueType() As Type
        Get
            ' Return the type of the value that CalendarCell contains.
            Return GetType(DateTime)
        End Get
    End Property

    Public Overrides ReadOnly Property DefaultNewRowValue() As Object
        Get
            ' Use the current date and time as the default value.
            Return DateTime.Now
        End Get
    End Property

End Class

설명

최적화 기술로, 일반적으로 동일한 형식의 모든 셀과 동일한 DataGridView 공유의 모든 셀은 호스트된 단일 편집 컨트롤을 공유합니다. 그러나 셀에서 컨트롤을 사용 하기 전에 메서드에 의해 InitializeEditingControl 초기화 해야 합니다. 처음 호출되면 이 메서드는 부모 DataGridView컨트롤의 편집 컨트롤 목록에 컨트롤을 추가합니다. 또한 셀의 시각적 속성 중 일부를 초기화합니다. 예를 들어 InitializeEditingControl 제공된 셀 스타일 매개 변수와 일치하도록 편집 영역의 배경색을 설정합니다. 후속 호출은 InitializeEditingControl 아무 것도 수행하지 않습니다.

파생 클래스는 이 메서드를 사용하여 해당 형식에 Control 해당하는 클래스의 인스턴스를 호스트합니다. 예를 들어 하나 이상의 DataGridViewTextBoxCell 개체가 포함된 테이블은 이 메서드를 호출하여 소유에 단일 TextBox 편집 컨트롤을 추가합니다 DataGridView.

적용 대상

추가 정보