RE: DateTimePicker on datagridView
To host a DateTimePicker in a DataGridView column you must define a new class
that inherits from DataGridViewColumn. You can find the whole class in the
documentation “How to: Host Controls in Windows Forms DataGridView Cells”,
it’s called CalendarColumn (in my machine, the cocumentation address is:
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_fxmclictl/html/e79a9d4e-64ec-41f5-93ec-f5492633cbb2.htm).
In the example you will find a form called Form1, you may take it off.
Copy the code, add a new item to the project of type class.vb, and paste the
code there.
Now, when creating the dataGridView, if you dropped it from the toolBox, you
must first remove the column from the DataGridView, since you will create the
column programmatically.
Then, in the Form’s Load Event Handler, you must write (suppose your
dataGridView control is called myDataGridView):
Dim CalendarCol As New CalendarColumn()
CalendarCol.Name = "<the name of the column>"
CalendarCol.DataPropertyName = "<the name of the field in the DataBase>"
myDataGridView.Columns.Add(CalendarCol)
Done.
Hope this helps!
--
Other_Developer_More
"Cenk" wrote:
> Hi all
>
> In table dtTasks there are 3 fields, ID, Name and birthDate.
> I fill dtTasks with adapter and bind it like below.
>
> dgview.DataSource = dtTasks;
>
> Code above automatically creates columns and insert rows to
> datagridview.
> At this point i want to select Birth date from dateTimePicker.
>
> I need a code that will make me use DateTimePicker for Birthdate
> column.
>
> But i don't want to add columns and rows manually.
>
> Thanks and best regards.
>
>
date: Mon, 6 Mar 2006 13:21:29 -0800
author: Other_Developer_More