Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Datagridview and datetimepicker

2 views
Skip to first unread message

Bob

unread,
Jun 7, 2006, 11:34:52 PM6/7/06
to
How can I make a column in a datagridview control contain a datetimepicker
control to enter or edit a date in a cell?

If its not asking too much I would appreciate an almost click by click
desvription or a snippet of code needed to do that. The datagridview I use
is bound.

Thanks in advance for any help,

Bob


Kevin Spencer

unread,
Jun 8, 2006, 8:01:16 AM6/8/06
to
Hi Bob,

Funny you should ask. The MSDN Online Library has an article about hosting
Controls in a DataGridView, which actually uses a DateTimePicker as an
example (with full code)! :)

http://msdn2.microsoft.com/en-us/7tas5c80.aspx

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

A lifetime is made up of
Lots of short moments.

"Bob" <bdu...@sgiims.com> wrote in message
news:u8WXCyqi...@TK2MSFTNGP04.phx.gbl...

Bob

unread,
Jun 10, 2006, 9:02:21 AM6/10/06
to
Thanks kevin
I tried te sample and that works fine BUT they dynamically create a single
column datagrid in te form. I ave an exusting datagrid that is already
bound and the column Mydate in that existinh datagrid is the one that
already has data and already is bound. That particular bit is what I'm
having a problem with. How do I host the existing calendar control class in
the existinu Mydate column.
The micrsoft code snpipet is basically as follows
Public Class Form1
Inherits Form

Private dataGridView1 As New DataGridView()

<STAThreadAttribute()> _
Public Shared Sub Main()
Application.Run(New Form1())
End Sub

Public Sub New()
Me.dataGridView1.Dock = DockStyle.Fill
Me.Controls.Add(Me.dataGridView1)
Me.Text = "DataGridView calendar column demo"
End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) _
Handles Me.Load

Dim col As New CalendarColumn()
Me.dataGridView1.Columns.Add(col)
Me.dataGridView1.RowCount = 5
Dim row As DataGridViewRow
For Each row In Me.dataGridView1.Rows
row.Cells(0).Value = DateTime.Now
Next row

End Sub

End Class

What do I need to do to have an EXISTING datagrid and an EXISTING column
display te datetimepicker in the calendarclass.

Thanks,
Bob


"Kevin Spencer" <ke...@DIESPAMMERSDIEtakempis.com> wrote in message
news:u6mBANvi...@TK2MSFTNGP04.phx.gbl...

Kevin Spencer

unread,
Jun 12, 2006, 11:09:55 AM6/12/06
to
Hi Bob,

I'm not following you. The sample creates 3 different classes: A
DataGridViewColumn, a DataGridViewCell, and a DataGridViewEditingControl.
Once these 3 classes are created, they are used together to populate a
column of a DataGridView Control. They also work exactly like any other
DataGridViewColumn Control, in that you really only work with the Column for
the most part, such as adding a Column to the Columns Collection, unless you
are working with individual Cells in a Row, in which case, you work with the
Cell. But in any case, you can set the value on a per-Cell basis the same
way you would with any other DataGridViewColumn-derived Control. There's no
difference.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

A lifetime is made up of
Lots of short moments.

"Bob" <bdu...@sgiims.com> wrote in message

news:Orjld4Ij...@TK2MSFTNGP03.phx.gbl...

0 new messages