This is a migrated thread and some comments may be shown as answers.

Custom cell TimePickerCellElement

1 Answer 52 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jose
Top achievements
Rank 1
Jose asked on 17 Feb 2020, 02:36 PM

Hello.

I'm tring to make a custom cell with radtimepickerelement but something is not working in SetContentCore because any value I set in the timepicker editor when i see the value it's always nothing.

 

And in the other hand I can't use the custom editor in the row witch is used for add new rows in the grid.

 

I've done a sample code if you could help me

Thx.

 

 

  Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
        Dim colnombre As New GridViewTextBoxColumn("nombre")
        Dim colHora As New TimePickerColumn("hora")

        GVPrueba.Columns.Add(colnombre)
        GVPrueba.Columns.Add(colHora)

        GVPrueba.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill


    End Sub

    Private Sub GVPrueba_SelectionChanged(sender As Object, e As EventArgs) Handles GVPrueba.SelectionChanged
        If GVPrueba.SelectedRows.Count = 1 Then

            If GVPrueba.SelectedRows(0).Cells("hora").Value IsNot Nothing Then
                MsgBox(GVPrueba.SelectedRows(0).Cells("hora").Value.ToString)

            End If
        End If
    End Sub




    Private Sub RadButton1_Click(sender As Object, e As EventArgs) Handles RadButton1.Click
        If GVPrueba.Rows.Count > 0 Then
            GVPrueba.Rows(0).Cells("hora").Value = Now
        End If
    End Sub


    Public Class TimePickerCellElement
        Inherits GridDataCellElement

        Public Sub New(ByVal column As GridViewColumn, ByVal row As GridRowElement)
            MyBase.New(column, row)
        End Sub

        Private oRadTimePickerElement As RadTimePickerElement
        Protected Overrides Sub CreateChildElements()
            MyBase.CreateChildElements()
            oRadTimePickerElement = New RadTimePickerElement()
            Me.Children.Add(oRadTimePickerElement)
        End Sub

        Protected Overrides Sub SetContentCore(value As Object)
            If Me.Value IsNot Nothing AndAlso Me.Value IsNot DBNull.Value Then
                DateTime.TryParse(value, oRadTimePickerElement.Value)
                '       MyBase.SetContentCore(value)
            End If
        End Sub

        Public Overrides Function IsCompatible(ByVal data As GridViewColumn, ByVal context As Object) As Boolean
            Return TypeOf data Is TimePickerColumn AndAlso (TypeOf context Is GridDataRowElement OrElse TypeOf context Is GridNewRowElement)
        End Function

    End Class

    Public Class TimePickerColumn
        Inherits GridViewDataColumn
        Public Sub New(ByVal fieldName As String)
            MyBase.New(fieldName)
        End Sub

        Public Overrides Function GetCellType(ByVal row As GridViewRowInfo) As Type
            If TypeOf row Is GridViewDataRowInfo Then
                Return GetType(TimePickerCellElement)
            End If
            Return MyBase.GetCellType(row)
        End Function

    End Class

 


1 Answer, 1 is accepted

Sort by
0
Nadya | Tech Support Engineer
Telerik team
answered on 20 Feb 2020, 11:46 AM

Hello Jose,

Thank you for the provided code snippet. It seems ok to me. However, I noticed that you do not assign editor and this is why you can not enter edit mode in your custom cell when adding a new row in the grid. You should subscribe to the EditorRequired event, which is triggered when a cell needs an editor and use an appropriate editor. In your case it is suitable to use the GridTimePickerEditor:

Private Sub RadGridView1_EditorRequired(sender As Object, e As EditorRequiredEventArgs)
    If RadGridView1.CurrentColumn.Name = "hora" Then
        e.EditorType = GetType(GridTimePickerEditor)
    End If
End Sub

I hope this helps. Let me know if I can assist you further.

Regards,
Nadya
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
Jose
Top achievements
Rank 1
Answers by
Nadya | Tech Support Engineer
Telerik team
Share this question
or