How to add datetimepicker in datagridview in Visual Basic?
<p>I have a datagridview (DataGridViewsalarydetail). It has 3 columns :</p>

<ol>
<li>Formula(only accept number and alphabet),  </li>
<li>Effective Date(only accept date ex:14/09/2016),</li>
<li>Basic Rate(only accept number and dot[.] for double).</li>
</ol>

<p>The problem is how to put the date time picker in data grid view OR how to set date column to only accept a valid date ?</p>

<p>I'm using Visual Basic Express 2015, MySQL, phpMyAdmin, and VB.NET</p>

<p>I have tried code from MSDN site, but I don't know how to implement in my project.</p>

<pre><code>Private Sub DataGridViewsalarydetail_EditingControlShowing(sender As Object, e As DataGridViewEditingControlShowingEventArgs) Handles DataGridViewsalarydetail.EditingControlShowing
        If TypeOf e.Control Is TextBox Then
            DirectCast(e.Control, TextBox).CharacterCasing = CharacterCasing.Upper
    End If

    If DataGridViewsalarydetail.CurrentCell.ColumnIndex = 0 Then

        AddHandler CType(e.Control, TextBox).KeyPress, AddressOf TextBox_keyPress

    ElseIf DataGridViewsalarydetail.CurrentCell.ColumnIndex = 1 Then

        AddHandler CType(e.Control, TextBox).KeyPress, AddressOf TextBox_keyPress2

    ElseIf DataGridViewsalarydetail.CurrentCell.ColumnIndex = 2 Then

        AddHandler CType(e.Control, TextBox).KeyPress, AddressOf TextBox_keyPress1

    End If

End Sub

Private Sub TextBox_keyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs)

    'If Char.IsDigit(CChar(CStr(e.KeyChar))) = False Then e.Handled = True

End Sub

Private Sub TextBox_keyPress1(ByVal sender As Object, ByVal e As KeyPressEventArgs)

    'If Not (Char.IsDigit(CChar(CStr(e.KeyChar))) Or e.KeyChar = ".") Then e.Handled = True
    e.Handled = True
    If e.KeyChar Like "." Or e.KeyChar = Chr(&amp;H8) Or IsNumeric(e.KeyChar) Then
        e.Handled = False
    End If

End Sub
Private Sub TextBox_keyPress2(ByVal sender As Object, ByVal e As KeyPressEventArgs)

    If Not (Char.IsDigit(CChar(CStr(e.KeyChar))) Or e.KeyChar = "/") Then e.Handled = True
    'e.Handled = True
    'If e.KeyChar Like "." Or e.KeyChar Like "/" Or e.KeyChar = Chr(&amp;H8) Or IsNumeric(e.KeyChar) Then
    '    e.Handled = False
    'End If

End Sub

Private Sub DataGridViewsalarydetail_CellValidating(sender As Object, e As DataGridViewCellValidatingEventArgs) Handles DataGridViewsalarydetail.CellValidating
    If e.ColumnIndex = 1 Then
        Dim dt As DateTime
        If e.FormattedValue.ToString &lt;&gt; String.Empty AndAlso Not DateTime.TryParse(e.FormattedValue.ToString, dt) Then
            MessageBox.Show("Enter correct Date")
            'Me.DataGridViewsalarydetail.Rows(e.RowIndex).ErrorText = "Enter a valid Date time"
            e.Cancel = True
        End If
    End If
End Sub
</code></pre>