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.
Syncfusion Feedback

Custom Format for DateTime not showing in DataBound GridListControl

Thread ID:

Created:

Updated:

Platform:

Replies:

102997 Mar 21,2012 02:49 PM UTC Mar 22,2012 11:42 AM UTC Windows Forms 1
loading
Tags: GridControl
Eric Robishaw
Asked On March 21, 2012 02:49 PM UTC

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.




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


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

;