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. (Last updated on : November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to format a date type column?

Thread ID:

Created:

Updated:

Platform:

Replies:

23802 Jan 20,2005 05:56 AM UTC Jan 21,2005 07:34 AM UTC WinForms 4
loading
Tags: GridControl
Phuoc Tu
Asked On January 20, 2005 05:56 AM UTC

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

Administrator [Syncfusion]
Replied On 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;
	}
}

Phuoc Tu
Replied On 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

Administrator [Syncfusion]
Replied On 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

Phuoc Tu
Replied On January 21, 2005 07:34 AM UTC

It works now. Thanks

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

;