dcsimg
Results 1 to 7 of 7
  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2016
    Posts
    13

    Resolved [RESOLVED] Datepicker for DGV

    Can anyone please direct me to a tutorial to include a datepicker in my VB.Net application's datagridview?

    I have searched but only seems to get sample codes for #C?

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    21,694

    Re: Datepicker for DGV

    It's a working example, but not well annotated, or described...

    http://www.vbforums.com/showthread.php?667661-dtpColumn

  3. #3
    Frenzied Member ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    1,063

    Re: Datepicker for DGV

    Hi Gideon,

    this will add a few thins to DGV (also a DatetimeP.)

    Code:
    Public Class Form2
    
        Private WithEvents dtp As New DateTimePicker
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            With DataGridView1
                Dim Key As String = "Column1"
                .Columns.Add(Key, Key)
                .Columns.Add(CreateComboBoxColumn)
                .Columns.Add(CreateButtonColumn)
                .Rows.Add(10)
            End With
    
            With dtp
                .Format = DateTimePickerFormat.Short
                .Width = 85
                .Visible = False
                Me.Controls.Add(dtp)
            End With
        End Sub
    
        Private Function CreateComboBoxColumn() As DataGridViewComboBoxColumn
    
            Dim column As New DataGridViewComboBoxColumn()
    
            With column
                .Name = "Title"
                .HeaderText = .Name
                .Items.AddRange(New String() {"Mr", "Mrs", "Dr."})
                .FlatStyle = FlatStyle.Flat
            End With
            Return column
        End Function
    
        Private Function CreateButtonColumn() As DataGridViewButtonColumn
    
            Dim Column As New DataGridViewButtonColumn
            With Column
                .ReadOnly = True
                .Width = 120
                .Name = "Column3"
                .HeaderText = "Date"
                .Width = 85
            End With
            Return Column
        End Function
    
    
        Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
    
            If e.ColumnIndex <> 2 Then
                Exit Sub
            End If
    
            With DataGridView1
                Dim r As Rectangle = .GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, False)
                dtp.Location = New Drawing.Point(.Left + r.Left, .Top + r.Top)
                dtp.Visible = True
                dtp.BringToFront()
                dtp.Focus()
                SendKeys.Send("{F4}")
            End With
        End Sub
    
        Private Sub dtp_CloseUp(ByVal sender As Object, ByVal e As System.EventArgs) Handles dtp.CloseUp
    
            Dim c As DataGridViewCell = DirectCast(dtp.Tag, DataGridViewCell)
            c.Value = dtp.Text
            dtp.Hide()
        End Sub
    
        Private Sub dtp_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles dtp.Enter
    
            Dim c As DataGridViewCell = DataGridView1.CurrentCell
            If c.Value IsNot Nothing Then
                dtp.Text = c.Value.ToString
            Else
                dtp.Value = Date.Today
            End If
            dtp.Tag = DataGridView1.CurrentCell
        End Sub
    End Class
    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  4. #4
    Junior Member HeribertoLugo's Avatar
    Join Date
    Nov 2014
    Posts
    29

    Re: Datepicker for DGV

    i think this is one of the best tutorials on how to do that

    https://docs.microsoft.com/en-us/dot...gridview-cells

  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    98,890

    Re: Datepicker for DGV

    Quote Originally Posted by HeribertoLugo View Post
    i think this is one of the best tutorials on how to do that

    https://docs.microsoft.com/en-us/dot...gridview-cells
    I just used Bing and Google to search for "vb.net datetimepicker datagridview". That page was the fourth result on Bing. On Google, the second result was an MSDN forums page that included a link to that page. There were also plenty of other VB results. I have to wonder exactly what the OP searched for to only find C# examples.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    Junior Member HeribertoLugo's Avatar
    Join Date
    Nov 2014
    Posts
    29

    Re: Datepicker for DGV

    Quote Originally Posted by jmcilhinney View Post
    I just used Bing and Google to search for "vb.net datetimepicker datagridview". That page was the fourth result on Bing. On Google, the second result was an MSDN forums page that included a link to that page. There were also plenty of other VB results. I have to wonder exactly what the OP searched for to only find C# examples.
    i am going to assume op didnt use vb.net in the keywords. you are right, there are tons of tuts on how to host custom controls in dgv columns.

    i posted the one i used to learn how to make custom columns..

  7. #7

    Thread Starter
    New Member
    Join Date
    Nov 2016
    Posts
    13

    Re: Datepicker for DGV

    Thank you everyone. It seems to be really easy. In design , smart tag change the column type to CalendarColumn.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width


×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.