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.

How to format a date type column?

Thread ID:

Created:

Updated:

Platform:

Replies:

23802 Jan 20,2005 12:56 AM Jan 21,2005 02:34 AM Windows Forms 4
loading
Tags: GridControl
Phuoc Tu
Asked On January 20, 2005 12:56 AM

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 01:53 AM

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 06:08 PM

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 01:19 AM

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 02:34 AM

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.

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.

;