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.

GGC format time cell

Thread ID:

Created:

Updated:

Platform:

Replies:

132733 Sep 18,2017 05:54 PM Sep 22,2017 06:22 AM Windows Forms 5
loading
Tags: GridGroupingControl
Josip Pejakovic
Asked On September 18, 2017 05:54 PM

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

Arulpriya Ramalingam [Syncfusion]
Replied On September 19, 2017 07:56 AM

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   


Josip Pejakovic
Replied On September 19, 2017 01:59 PM

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?


Arulpriya Ramalingam [Syncfusion]
Replied On September 20, 2017 05:47 AM

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 


Josip Pejakovic
Replied On September 21, 2017 01:59 PM

Thanks for support! Problem solved!


Arulpriya Ramalingam [Syncfusion]
Replied On September 22, 2017 06:22 AM

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 


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.

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.

;