date in datagrid

carla

Member
Joined
May 28, 2007
Messages
6
Programming Experience
3-5
Is it possible to format a date datagrid field in order to appear the calendar control? How?

Thanks,

Carla
 
VB.NET:
Private Sub dgMtnc_MouseClick(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) Handles dgMtnc.MouseClick

        Try
            'Get size and location of grid cell
            Dim cb As New System.Drawing.Rectangle() 'cell bounds

            'dgMtnc.CurrentCell.ColumnNumber = 0
            If dgMtnc.CurrentCell.ColumnIndex() = 0 Then 'Column 0 clicked
                If Not cc.Tag = "Open" Then 'Do once
                    'cc.Size = New Size(30, 30)

                    cb = dgMtnc.CurrentCell.ContentBounds
                    'GetCellDisplayRectangle, cell bounds

                    cc.Location = New Point(cb.X, cb.Y)
                    'Location for month control

                    dgMtnc.Controls.Add(cc)
                    'Add the month control

                    cc.Tag = "Open"

                    cc.BringToFront()
                    'must add the events you want to use 
                    AddHandler cc.DateSelected, AddressOf cc_DateSelected
                Else
                    'Same as above "without addhandler if control is already open
                    'cb = dgTest.GetCellBounds(dgTest.CurrentRowIndex, 0)
                    cb = dgMtnc.CurrentCell.ContentBounds
                    cc.Location = New Point(cb.X, cb.Y)
                    cc.BringToFront()
                    cc.Tag = "Open"
                End If
                cc.Show() 'Show the control
            Else : cc.Hide()
            End If
        Catch ex As Exception

        End Try


    End Sub

  Private Sub cc_DateSelected(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles cc.DateSelected
        Try
            'Put selected date in selected cell then hide control
            dgMtnc.CurrentRow.Cells(0).Value = DirectCast(cc.SelectionStart.Date, Date)
            
            cc.Hide()
        Catch ex As Exception

        End Try

    End Sub
change dgMtnc with your datagridview name, i hope it help you :D
and If dgMtnc.CurrentCell.ColumnIndex() = 0 <<change column index with your column index where you want to show it
 
Last edited by a moderator:
Back
Top