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
close icon

GGC format time cell

Hello,

I have field in table which is DateTime type (mySQL). How to set GGC cell to show only HH:mm format and how to modify value using MaskEdit?

At this moment this is setting that I hafve for property AnyRecordFieldCell:

CellType = "MaskEdit"
CellValueType = System.DateTime
Format = "HH:mm"
ValueMember = "RecTime"
DisplayMember = "RecTime"

but when I load data displayed value is like dd.MM.yyyy HH:mm:ss and it should be like HH:mm

5 Replies

AR Arulpriya Ramalingam Syncfusion Team September 19, 2017 11:56 AM UTC

Hi Josip,   
   
Thanks for using Syncfusion products.   
   
The MaskEdit CellType can be used to create custom format types and the Mask must be a string composed of one or more of the masking elements. So, the DateTime value will as dd/MM/yyyy HH:MM:SS could not be masked as HH:MM. Please refer to the below link to know more about the masking elements,    
   
Suggestion 1   
In order to display only the time value of DateTime cell, the Format property of GridStyleInfo can be set as “HH:MM” and there is no need to set the cell type as “MaskEdit”. Please refer to below code and sample,   
   
Code example:  
   
//To set the format for the time   
this.gridGroupingControl1.TableDescriptor.Columns["DateTime"].Appearance.AnyRecordFieldCell.Format = "HH:MM";   
 
   
Suggestion 2   
   
The QueryCellStyleInfo event can also be used to set format for the DateTime column. Please refer to the below code and sample,   
   
Code example:  
   
//Event Customization   
private void GridGroupingControl1_QueryCellStyleInfo(object sender,GridTableCellStyleInfoEventArgs e)   
{   
    if(e.TableCellIdentity.RowIndex > 0 && e.TableCellIdentity.Column !=null && e.TableCellIdentity.Column.Name == "DateTime" && e.Style.CellType !="ColumnHeaderCell")   
    {   
        //To set the format for the time   
        e.Style.Format = "HH:MM";   
    }   
}   
 
   
   
Regards,   
Arulpriya   



JO Josip September 19, 2017 05:59 PM UTC

Thanks, it works on this way. But there is another thing. Now it appears dropdown button and when I click on it the calendar appears.

How to show time picker instead of calendar? Or even better how to set automatically current time in cell while adding new row?



AR Arulpriya Ramalingam Syncfusion Team September 20, 2017 09:47 AM UTC

Hi Josip,  
  
Thanks for your update.  
  
Query  
Response  
Now it appears dropdown button and when I click on it the calendar appears.  
How to show time picker instead of calendar?  
By default, the DateTime column will be added as MonthCalendar in GridGroupingControl. We regret to let you know that the GridGroupingControl does not have the support to customize the DateTime drop down to select only the time value.  

Note:  
The dropdown button can be hidden by using ShowButtons property of GridStyleInfo. Please refer to below code,  
  
//To hidde the drop down button  
this.gridGroupingControl1.TableDescriptor.Columns["DateTime"].Appearance.AnyRecordFieldCell.ShowButtons = GridShowButtons.Hide;  
  
Or even better how to set automatically current time in cell while adding new row?  
Suggestion 1  
In order to add the current time in the AddNewRecord row, the ShowDefaultValuesInAddNewRecord property can be set to true and the DefaultValue property can be used to set the default value on the AddNewRecord row. The default value can be updated by using the CurrentRecordContextChange event. Please refer to the below code and sample,  
  
//To Show the default value on AddNewRecord row  
this.gridGroupingControl1.ShowDefaultValuesInAddNewRecord = true;  
  
//By using CurrentRecordContextChange event  
private void GridGroupingControl1_CurrentRecordContextChange(object sender,CurrentRecordContextChangeEventArgs e)  
{  
    if(e.Table.CurrentRecord != null && e.Table.CurrentRecord.Kind == DisplayElementKind.AddNewRecord)  
    {  
        //To set the default value  
        this.gridGroupingControl1.TableDescriptor.Fields["DateTime"].DefaultValue =DateTime.Now.ToShortTimeString();  
    }  
}  
  
  
Suggestion 2  
The TableControlCurrentCellMoved event can also be used to update the time in AddNewRecordRow. Please refer to the below code and sample,  
  
//By using TableControlCurrentCellMoved event  
private void GridGroupingControl1_TableControlCurrentCellMoving(object sender,GridTableControlCurrentCellMovingEventArgs e)  
{  
    if(e.TableControl.Table.CurrentRecord != null && e.TableControl.Table.CurrentRecord.Kind ==DisplayElementKind.AddNewRecord)  
    {  
        //To set the default value  
        this.gridGroupingControl1.TableDescriptor.Fields["DateTime"].DefaultValue =DateTime.Now.ToShortTimeString();  
    }  
}  
  
  
  
  
  
Please let us know if you have any other queries  
  
Regards,  
Arulpriya 



JO Josip September 21, 2017 05:59 PM UTC

Thanks for support! Problem solved!



AR Arulpriya Ramalingam Syncfusion Team September 22, 2017 10:22 AM UTC

Hi Josip, 
  
Thanks for your update. 
  
We are glad to hear that the provided solution was resolved your scenario. 
  
Please let us know, if you have any other queries. 
  
Regards, 
Arulpriya 


Loader.
Live Chat Icon For mobile
Up arrow icon