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

How to format a date type column?

Hi all, Please help me: 1. Format a date type column: MM/dd/yyyy? 2. If the value of date type column is null, how to show 00/00/0000 on grid? Thanks, Phuoc Tu

4 Replies

AD Administrator Syncfusion Team January 20, 2005 06:53 AM UTC

1) If you set the style.CellValueType for the column to typeof(DataTime), then you set style.Format for the column to specify. If this is a GridControl, you set the style for the column using the grid.ColStyles collection. If this is a GridDataBoundGrid, you set the column style using either grid.GridBoundColumn[col].StyleInfo or grid.Binder.InternalColumns[col].StyleInfo depending upon whether you have esplicitly added GridBoundColumns or not. 2) You can handle the QueryCellFormattedText event and specify the display value there.
private void gridControl1_QueryCellFormattedText(object sender, GridCellTextEventArgs e)
{
	if(e.Style.CellValueType == typeof(DateTime)&& e.Style.Text.Length == 0)
	{
		e.Text = "00/00/0000";
		e.Handled = true;
	}
}


PT Phuoc Tu January 20, 2005 11:08 PM UTC

I am using DataBoundGrid. I don''t find out "QueryCellFormattedText" event. Which event instead of? Can you give me a example with DataBoundGrid. Thanks, Phuoc Tu


AD Administrator Syncfusion Team January 21, 2005 06:19 AM UTC

In a GridDataBoundGrid, QueryCellFormattedText is a member of the Model class. So, you subscribe to it using //c# this.grid.Model.QueryCellFormattedText += new GridCellTextEventHandler(Model_QueryCellFormattedText) ''vb AddHandler Me.grid.Model.QueryCellFormattedText, AddressOf Model_QueryCellFormattedText


PT Phuoc Tu January 21, 2005 07:34 AM UTC

It works now. Thanks

Loader.
Live Chat Icon For mobile
Up arrow icon