DataGridViewCell.DefaultNewRowValue 속성

정의

새 레코드에 대한 행의 셀 기본값을 가져옵니다.

public:
 virtual property System::Object ^ DefaultNewRowValue { System::Object ^ get(); };
[System.ComponentModel.Browsable(false)]
public virtual object DefaultNewRowValue { get; }
[System.ComponentModel.Browsable(false)]
public virtual object? DefaultNewRowValue { get; }
[<System.ComponentModel.Browsable(false)>]
member this.DefaultNewRowValue : obj
Public Overridable ReadOnly Property DefaultNewRowValue As Object

속성 값

기본값을 나타내는 Object입니다.

특성

예제

다음 코드 예제에서 파생 되는 클래스에서 속성을 재정의 DefaultNewRowValueCalendarCell 하는 방법을 보여 줍니다 DataGridViewTextBoxCell. 이 예제는 방법: 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

설명

기본 클래스 DataGridViewCell 의 속성은 DefaultNewRowValue 항상 를 반환합니다null. 그러나 다른 기본값을 반환하기 위해 파생 셀 클래스에서 이 속성을 재정의할 수 있습니다.

셀이 새 레코드의 행에 있는 경우 이 속성에서 반환된 값이 표시됩니다. 포커스가 새 레코드의 행에 들어갈 때 이벤트에 대한 DataGridView.DefaultValuesNeeded 처리기에서 이 값을 재정의할 수 있습니다.

적용 대상

추가 정보