How can I display a DateTimePicker in a DataGridView?

后端 未结 6 930
无人及你
无人及你 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:27

    Maybe this isn't proper, but easy trick and same result........ lot less code......I was just playing around and though outside the box, just set

    I hide mine until they click cell, or you can show First I declared :

    DateTimePicker1.Visible = False
    

    when you click in cell, run this code...

        DateTimePicker1.Visible = True
        ActiveControl = DateTimePicker1
    

    Then below

     Public Sub DateTimePicker1_ValueChanged(sender As System.Object, e As System.EventArgs) Handles DateTimePicker1.ValueChanged
    
    
    
        requestDGV.Rows(0).Cells("requestTimeOff").Value = (DateTimePicker1.Value)
        DateTimePicker1.Visible = False
        DateTimePicker1.Enabled = False
    
    End Sub
    

    Super Basic , and i have it sitting directly in the box, doesn't look out of place

    Or super easy mode.......I just like to hide mine till column click

    Public Sub DateTimePicker1_ValueChanged(sender As System.Object, e As System.EventArgs) Handles DateTimePicker1.ValueChanged
    
    
        requestDGV.Rows(0).Cells("requestTimeOff").Value = (DateTimePicker1.Value)
    
    End Sub
    

    You really just need that one line.....data will be in the grid, just a lot less code.....

提交回复
热议问题