How can I display a DateTimePicker in a DataGridView?

后端 未结 6 928
无人及你
无人及你 2020-12-09 15:50

Is there any way to put a DateTimePicker control in the DataGridView?

I checked all the possible properties but it give option of checkbox, combo box etc, but not th

6条回答
  •  青春惊慌失措
    2020-12-09 16:35

    Ok... Using some of @rajat and @Aaron examples, i made one that pops up on the DateTimePicker cell. Thanks everyone.

    Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
    
        If e.ColumnIndex = 8 Then 'CHECK IF IT IS THE RIGHT COLUMN
    
            'SET SIZE AND LOCATION
            Dim rect = DataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, True)
            DateTimePicker1.Size = New Size(rect.Width, rect.Height)
            DateTimePicker1.Location = New Point(rect.X + 10, rect.Y + 76) 'USE YOU OFFSET HERE
    
            DateTimePicker1.Visible = True
            ActiveControl = DateTimePicker1
    
        End If
    
    End Sub
    
    
    Private Sub DateTimePicker1_ValueChanged(sender As Object, e As EventArgs) Handles DateTimePicker1.ValueChanged
    
        If DataGridView1.RowCount > 0 Then 'JUST TO AVOID FORM LOAD CRASH
    
            DataGridView1.CurrentCell.Value = DateTimePicker1.Value.ToShortDateString
            DateTimePicker1.Visible = False
    
        End If
    

提交回复
热议问题