We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to set focus to a specific part of the DateTimeEdit column?

Platform: WPF |
Control: GridDataControl |
.NET Framework: 4.5

GridDataControl provides support for GridDateTimeColumn, incorporating DateTimeEdit controls in its cells and it helps you to interactively set a date and time value. In GridDateTimeColumn by default, when you enter into Edit mode in DateTimeEdit cell, focus is set to the first part of DateTime. In the following screenshot, the first part (month) is focused when you enter into Edit mode .

Figure 1: First Part (month) is focused by default

You can customize this behavior by overriding the corresponding GridCellDateTimeEditCellRenderer and GridCellModel class. The cellmodel class just creates the cell type by calling the cellrenderer. For customizing the focus, you need to wire the loaded event of the corresposnding uielement, such as, DateTimeEdit in the OnWireUIElement method. In the loaded event of the uielement, you can change the focus to specific parts, by changing the SelectionStart and SelectionLength values.

The following code example explains how you can change selection range in a loaded event.


Now create a new cell model class that is derived from GridCellModel and pass the custom cell renderer class as the Generic parameter of this GridCellModel.

The following code example explains how to override the GridCellModel class.


After this, you can remove the old cell model and add a new custom cell model into the CellModels Collection.

The following code snippet demonstrates adding custom cell model in the CellModels collection.


The following screenshot illustrates the customized focus in GridDateTimeColumn.

Figure 2:Date is focused when entered in Edit mode

You can refer the sample from the following location.

Link: DateTimeEdit_WPF

2X faster development

The ultimate WPF UI toolkit to boost your development speed.
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile