-
Dec 24th, 2017, 01:14 AM
#1
Thread Starter
Addicted Member
[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?
-
Dec 24th, 2017, 01:30 AM
#2
Re: Datepicker for DGV
It's a working example, but not well annotated, or described...
http://www.vbforums.com/showthread.php?667661-dtpColumn
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Dec 24th, 2017, 04:33 AM
#3
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.
-
Dec 25th, 2017, 02:42 AM
#4
Junior Member
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
-
Dec 25th, 2017, 09:37 AM
#5
Re: Datepicker for DGV
Originally Posted by HeribertoLugo
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.
-
Dec 25th, 2017, 06:10 PM
#6
Junior Member
Re: Datepicker for DGV
Originally Posted by jmcilhinney
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..
-
Dec 26th, 2017, 02:06 AM
#7
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|