How to stop GridViewMaskBoxColumn from autofilling the current date?

1 Answer 74 Views
GridView
Mark
Top achievements
Rank 1
Mark asked on 30 Jun 2023, 06:08 PM

Hello,

I have a RadGridView with a GridViewMaskBoxColumn that has a DateTime mask of 'd', EnableNullValueInput set to true, and MaskType set to FreeFormDateTime. The CTRL+DEL does clear the box, but when I leave the box the current date is automagically filled. In CellValidating, CellValueChanged, CellValueNeeded, and UserAddingRow I assign the cell value to null if there is no current value in the cell or if it's whitespace or if it's an empty string. 

I see on this Parsing Dates Page under Date evaluation that "incomplete dates are always evaluated taking the current date as a basis". Can I override this behavior so a null cell can stay a null cell? If yes, how?

 

Thank you.

1 Answer, 1 is accepted

Sort by
0
Accepted
Dinko | Tech Support Engineer
Telerik team
answered on 05 Jul 2023, 10:59 AM

Hello Mark,

Thank you for the provided details.

In general, the business object property to which the column is pointing needs to accept null values. For example, here is my test class with nullable DateTime property.

public class GridItem 
{
    private DateTime? currentDate;

    public DateTime? CurrentDate
    {
        get { return currentDate; }
        set { currentDate = value;}
    }       
}

Now let's set up the column:

GridViewMaskBoxColumn maskBoxColumn = new GridViewMaskBoxColumn();
maskBoxColumn.Name = "CurrentDate";
maskBoxColumn.FieldName = "CurrentDate";
maskBoxColumn.HeaderText = "Current Date";
maskBoxColumn.MaskType = MaskType.DateTime;
maskBoxColumn.Mask = "d";
maskBoxColumn.EnableNullValueInput = true;
radGridView1.MasterTemplate.Columns.Add(maskBoxColumn);

Upon running the project and deleting the cell value using the CTRL+DEL, the cell becomes null.

You can check in your application if the property which the column is bound for is accepting null values. If yes, can you modify the attached project so that I can have a better look at your set-up you mentioned that you have custom logic in several RadGridView events.

Regards,
Dinko | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
GridView
Asked by
Mark
Top achievements
Rank 1
Answers by
Dinko | Tech Support Engineer
Telerik team
Share this question
or