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

Custom Format for DateTime not showing in DataBound GridListControl

Using the GridListControl, I have set the DataSource to a list of Business Objects, including some properties with DateTime.

I want to show the DateTime columns using a custom format.

I have tried the following WITHOUT SUCCESS:
gridListControl1.Grid.Model.ColStyles[3].Format = customformat;
gridListControl1.Grid.ColStyles[3].Format = customformat;

with either of the above, immediately after setting the Format, if I read the value of Format it has not taken. For these data bound datetime columns it reads the default value of "d" always.

I've tried setting these values both before and after databinding, but no effect.

I have been able to get the grid to display the data by wiring to the Grid's Grid_DrawCellDisplayText event, and manually setting the value using e.DisplayText = ((DateTime)e.Style.CellValue).ToString(customformat).

This however is less than desireable for 2 reasons:
1) if I try to auto-width these columns, the internal date only value is being used for the column width, thus hiding the time portion
2) If I copy the grid to the clipboard and paste into excel, I only get the date values.




1 Reply

MC Mercy C Syncfusion Team March 22, 2012 11:42 AM UTC

Hi Eric,

Thanks for your interest in syncfusion products.

You can make use of "QueryCellInfo" event to set the format.

void Model_QueryCellInfo(object sender, Syncfusion.Windows.Forms.Grid.GridQueryCellInfoEventArgs e)
{
if (e.ColIndex == 5 && e.RowIndex > 0)
{
e.Style.Format = DateTime.Now.ToString("hh:mm");
}
}

Please refer to the sample in the following link
http://www.syncfusion.com/downloads/Support/DirectTrac/86979/WindowsFormsApplication69-1839979469.zip

Regards,
Mercy.C


Loader.
Live Chat Icon For mobile
Up arrow icon