Ver Mensaje Individual
  #3 (permalink)  
Antiguo 20/02/2008, 11:55
Avatar de juanutcm
juanutcm
Usuario no validado
 
Fecha de Ingreso: marzo-2005
Mensajes: 194
Antigüedad: 19 años, 2 meses
Puntos: 0
Solucion DateTimePicker en DataGridView Parte II

ESTE SEGMENTO DE CODIGO SE INSERTA EN LA CLASE PRINCIPAL DEL FORMULARIO EJ.:
Public Class Form1
SEGMENTO DE CODIGO QUE APARECE ABAJO
End Class

Código:
Public Class CalendarColumn
Inherits DataGridViewColumn
 
Public Sub New()
MyBase.New(New CalendarCell())
End Sub
 
Public Overrides Property CellTemplate() As DataGridViewCell
Get
Return MyBase.CellTemplate
End Get
Set(ByVal value As DataGridViewCell)
 
' Ensure that the cell used for the template is a CalendarCell.
If (value IsNot Nothing) AndAlso _
Not value.GetType().IsAssignableFrom(GetType(CalendarCell)) _
Then
Throw New InvalidCastException("Must be a CalendarCell")
End If
MyBase.CellTemplate = value
 
End Set
End Property
 
End Class
 
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)
If Me.Value.ToString <> Nothing Then
 
ctl.Value = CType(Me.Value, DateTime)
Else
ctl.Value = Today
End If
End Sub
 
Public Overrides ReadOnly Property EditType() As Type
Get
' Return the type of the editing contol 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