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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to autocomplete datatime cell

Thread ID:

Created:

Updated:

Platform:

Replies:

129915 Apr 10,2017 04:15 AM Apr 12,2017 07:01 AM Windows Forms 3
loading
Tags: GridGroupingControl
hieudt
Asked On April 10, 2017 04:15 AM

In GGC, I have cell with type is DateTime. I want when I type date value and leave, GGC auto fill month and year value, i.e type 10 and result 10/04/2017. How can I do this ?

Thanks

Piruthiviraj Malaimelraj [Syncfusion]
Replied On April 11, 2017 07:28 AM

Hi Hieudt, 
 
Thanks for your interest in Syncfusion products. 
 
We could able to understand your scenario. Currently the GridGroupingControl does not have the direct support to autocomplete the date values. This scenario can be achieved by creating the CustomCellType using GridDropDownMonthCalendarCellModel and GridDropDownMonthCalendarCellRenderer. Please make use of the below code. 
 
Code example: 
//Create CustomCellModel 
class DateTimeExt1Model : GridDropDownMonthCalendarCellModel 
{ 
    public DateTimeExt1Model(GridModel grid) 
        : base(grid) 
    { 
    } 
    public override bool ApplyFormattedText(GridStyleInfo style, string text, int textInfo) 
    { 
        string month; 
        string year; 
        DateTime isDate; 
        //To set the month and year of previous value. 
        if (style.Text != string.Empty && DateTime.TryParse(style.CellValue.ToString(),out isDate) && text.Length<=2) 
        { 
            DateTime time = (DateTime)style.CellValue; 
            month = time.Month.ToString(); 
            year = time.Year.ToString(); 
            month += "-" + text + "-" + year; 
        } 
        //To set the current month and year 
        else if (text.Length <= 2) 
        { 
            month = DateTime.Now.Month.ToString(); 
            year = DateTime.Now.Year.ToString(); 
 
            month += "-" + text + "-" + year; 
        } 
        else 
            month = text; 
        return base.ApplyFormattedText(style, month, textInfo); 
    } 
    public override GridCellRendererBase CreateRenderer(GridControlBase control) 
    { 
        return new DateTimeExt1Renderer(control, this); 
    } 
} 
 
//Adding CustomCellModel 
this.gridGroupingControl1.TableModel.CellModels.Add("DateTimeExt", new DateTimeExtModel(this.gridGroupingControl1.TableModel)); 
 
this.gridGroupingControl1.TableDescriptor.Columns["Description"].Appearance.AnyRecordFieldCell.CellType = "DateTimeExt"; 
this.gridGroupingControl1.TableDescriptor.Columns["Description"].Appearance.AnyRecordFieldCell.CellValueType = typeof(DateTime); 
this.gridGroupingControl1.TableDescriptor.Columns["Description"].Appearance.AnyRecordFieldCell.Format = "dd/MM/yyyy"; 
this.gridGroupingControl1.TableDescriptor.Columns["Description"].Appearance.AnyRecordFieldCell.ShowButtons = GridShowButtons.Hide; 
 
 
 
Sample link: 

Note: 
In above solution , we have provided the solution to autocomplete the date value with (current month & current year) and (also with month & year of previous value before editing). If you want to complete the date value with current month and year always, please remove the below highlighted code. 

public override bool ApplyFormattedText(GridStyleInfo style, string text, int textInfo) 
{ 
    string month; 
    string year; 
    DateTime isDate; 
    //To set the month and year of previous value. 
    if (style.Text != string.Empty && DateTime.TryParse(style.CellValue.ToString(),out isDate) && text.Length<=2) 
    { 
        DateTime time = (DateTime)style.CellValue; 
        month = time.Month.ToString(); 
        year = time.Year.ToString(); 
        month += "-" + text + "-" + year; 
    } 
    //To set the current month and year 
    else if (text.Length <= 2) 
    { 
        month = DateTime.Now.Month.ToString(); 
        year = DateTime.Now.Year.ToString(); 
 
        month += "-" + text + "-" + year; 
    } 
    else 
        month = text; 
    return base.ApplyFormattedText(style, month, textInfo); 
} 

Regards, 
Piruthiviraj

hieudt
Replied On April 12, 2017 12:36 AM

It works, thanks for your great help!

Piruthiviraj Malaimelraj [Syncfusion]
Replied On April 12, 2017 07:01 AM

Hi Hieudt, 

Thanks for your update. 

We are glad to hear that the provided solution is resolved your scenario. Please let us know if you have any other queries. 

Regards, 
Piruthiviraj 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

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

;