Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > How can I add a DateTime picker to a binded DataGridView?
 

How can I add a DateTime picker to a binded DataGridView?

I have a datagridview thats binded to a data source.   I have a column that is a DateTime and I'd like to use a DateTime picker to display the date and also give the user an easy way to select a new date when they add new items.

I'm using VB.net 2005

I've found lots of examples of doing this in C# but not for VB

cheers,
NateZilla77

NateZilla77  Tuesday, October 06, 2009 6:51 PM
Something like this should get you started:

http://www.mindfiresolutions.com/DateTime-Picker-Cell-in-DataGridView-317.php

Hope this helps.
www.insteptech.com ; msmvps.com/blogs/deborahk
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
DeborahK  Tuesday, October 06, 2009 7:10 PM

Hi NateZilla,

 

Do you mean the DataGridViewDateTimePickerColumn used in databinding mode?

 

I have tested the sample given by DeborahK, it works great. You can copy all the code into a cs file and use CalendarColumn this way.

Public Class Form1

    Private dtSource As DataTable = New DataTable()

 

    Public Sub New ()

        InitializeComponent()

 

        dtSource.Columns.Add("DateTimeCol" , GetType (String ))

        dtSource.Rows.Add(System.DateTime.Today.ToShortDateString())

 

        Dim calColumn As CalendarColumn = New CalendarColumn()

        calColumn.DataPropertyName = "DateTimeCol"

        DataGridView1.Columns.Add(calColumn)

 

        DataGridView1.DataSource = dtSource

    End Sub

End Class

 

Thank for DeborahK’s sharing. Hope this helps you NateZilla. If you have anything unclear, please feel free to tell me.

 

Sincerely,

Kira Qian

Send us any feedback you have about the help from MSFT at fbmsdn[At]microsoft.com


Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework!
Kira Qian  Wednesday, October 07, 2009 3:56 AM
OK, I see what I have to do and I can get the calendar to show up in the datagrid, now my problem is the datagrid data source. I added the code from deborah into a class. I then added the code from Kira Qian into my form1 and everything cleared up. I just need to sort out the datasource I have the datagrid already binded to a table adapter from my dataset.xsd. Should I not do this?
NateZilla77  Wednesday, October 07, 2009 2:00 PM
Hi NateZilla,

> I just need to sort out the datasource I have the datagrid already binded to a table adapter from my dataset.xsd.

Do you mean you have set the DataSource property of DataGridView in the VS PropertyGrid? If so I think the only thing you need to do is set the DataPropertyName property to the column name of that date time column. If you have any difficulty about it, please post some code to let us know your project clearly.

Sincerely,
Kira Qian
Send us any feedback you have about the help from MSFT at fbmsdn[At]microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework!
Kira Qian  Thursday, October 08, 2009 2:22 AM

You can use google to search for other answers

Custom Search

More Threads

• Better practice by deleting ???
• DataTable internal index corrupted
• configure dataadapter at design time in separate class
• Problem dynamically changing column Header Text on a Gridview
• problem with dataview sort
• Reuse of Typed Dataset for different project
• DataGridView With UserControl
• Read Data and Save as .CSV File
• modify gridview according to listbox
• Adding Column Data To New DataGridView Row