DataGridViewCell.InitializeEditingControl Methode
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Initialiseert het besturingselement dat wordt gebruikt om de cel te bewerken.
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);
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)
Parameters
- rowIndex
- Int32
De rijindex op basis van nul van de locatie van de cel.
- initialFormattedValue
- Object
Een Object waarde die de waarde vertegenwoordigt die door de cel wordt weergegeven bij het bewerken wordt gestart.
- dataGridViewCellStyle
- DataGridViewCellStyle
Een DataGridViewCellStyle die de stijl van de cel aangeeft.
Uitzonderingen
Er is geen gekoppeld DataGridView of als er een aanwezig is, heeft het geen gekoppeld besturingselement voor bewerken.
Voorbeelden
In het volgende codevoorbeeld ziet u hoe u de InitializeEditingControl methode overschrijft in een eenvoudige klasse die is afgeleid van de DataGridViewTextBoxCell klasse. Dit voorbeeld maakt deel uit van een groter codevoorbeeld in Hoe to: Hostbesturingselementen in Windows Forms DataGridView-cellen.
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
Opmerkingen
Als optimalisatietechniek delen doorgaans alle cellen van hetzelfde type en in hetzelfde DataGridView deel één gehost besturingselement voor bewerken. Voordat het besturingselement echter door een cel wordt gebruikt, moet het worden geïnitialiseerd door de InitializeEditingControl methode. De eerste keer dat het wordt aangeroepen, voegt deze methode het besturingselement toe aan de lijst met bewerkingsbesturingselementen in het bovenliggende DataGridViewbesturingselement. Ook worden enkele visuele eigenschappen van de cel geïnitialiseerd. Stelt bijvoorbeeld InitializeEditingControl de achtergrondkleur van het bewerkingsgebied in zodat deze overeenkomt met de opgegeven parameter voor celstijlen. Volgende aanroepen om niets te InitializeEditingControl doen.
Afgeleide klassen gebruiken deze methode om een exemplaar van de Control klasse te hosten dat overeenkomt met hun type. Een tabel met een of meer DataGridViewTextBoxCell objecten roept deze methode bijvoorbeeld aan om één TextBox besturingselement voor bewerken toe te voegen aan de eigenaar DataGridView.