.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Articles >> WPF >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Add DatePicker control In DataGrid In WPF

Posted By:Diptimaya Patra       Posted Date: April 18, 2010    Points: 25    Category: WPF    URL: http://www.dotnetspark.com  

Add DatePicker In DataGrid In WPF. Date Picker is a control available in WPF Toolkit. In this article we would see how we can use DatePicker in DataGrid in WPF.


Date Picker is a control available in WPF Toolkit. In this article we would see how we can use DatePicker in DataGrid in WPF.

Crating WPF Application Project

Fire up Visual Studio 2008 and Create a WPF Application and name the project as DatePickerDGWPF.


Here is the basic idea of our sample application; we will have sample data with one or more datetime properties, which will be displayed in DataGrid.
When the DateTime cell will be in edit mode we will display the DatePicker in the cell instead of TextBox, which is by default.

So let's have a class and have sample data.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace DatePickerDGWPF
    public partial class Window1 : Window
        public Window1()
            List ticketList = new List 
                new TicketInfo{ Subject="IE not working", RaisedBy="User 1", 
                new TicketInfo{ Subject="VSTS not working", RaisedBy="User 8", 
                new TicketInfo{ Subject="TFS not working", RaisedBy="User 5", 
                new TicketInfo{ Subject="Service not working", RaisedBy="User 2", 
                new TicketInfo{ Subject="SQL Server not working", RaisedBy="User 9", 
                new TicketInfo{ Subject="Portal not working", RaisedBy="User 2", 
                new TicketInfo{ Subject="Cannot login to portal", RaisedBy="User 7", 
            dgData.ItemsSource = ticketList;

    public class TicketInfo
        public string Subject { get; set; }
        public string RaisedBy { get; set; }
        public DateTime RaisedOn { get; set; }

Now we will add a DataGrid to the Window and design the Columns inside of it.


Code view of the above image





It seems we are done with the design of our DataGrid columns.

Run the application and try to edit the column "Raised On", you would get DatePicker control to handle the Date and Time.



You can also download the sample code used in the above example

Hope this article helps.

 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend