Using TextEditSettings.DisplayFormat To Format Your Data In DevExpress DataGrid

07-03-2012
//
http://pagead2.googlesyndication.com/pagead/show_ads.js

Devexpress doesn’t provide much information about how you can use this to format your data when you use DevExpress DataGrid.

I have a code to create and format a devexpress datagrid dynamically at run time. I had to automatically format date to match the British system if the current data is of type DateTime.

Basically, what you have to use as the string for the Display format is exactly what you would use if you were using the good old String.Format method in .net.

For example, if you wan to format your date value to appear like : 07-Feb-1999 then use the display format string : “dd-MMM-yyyy”

You can rest assured this works because the devexpress internal code calls the String.Format to do the formatting and use the display format string you provided for that. So as long as your string works with String.Format it will work with DevExpress as well.

case ColumnDataType.DATETIME:
 DevExpress.Xpf.Editors.Settings.DateEditSettings _txtEdDate = new DevExpress.Xpf.Editors.Settings.DateEditSettings();
 _txtEdDate.HorizontalContentAlignment = DevExpress.Xpf.Editors.Settings.EditSettingsHorizontalAlignment.Right;
 _txtEdDate.DisplayFormat = "dd-MMM-yyyy";  //  <-- Formatting string
_newCol.EditSettings = _txtEdDate;
break;

What DevExpress Says:
“An editor’s value is formatted using string.Format(“{0:DisplayFormat}, BaseEdit.EditValue). The specified display format should match the value’s type (Example 1). Otherwise, it is ignored and is not applied”

You don’t have to include things like “{0:” or braces “}” because DevExpress code does that for you. However, I checked and it would not crash even if you include those.
//
http://pagead2.googlesyndication.com/pagead/show_ads.js

Was this post helpful to you? How can I improve? – Your comment is highly appreciated!

Cassian Menol Razeek

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: