Tag: syntax

Using TextEditSettings.DisplayFormat To Format Your Data In DevExpress DataGrid

07-03-2012


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.

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

Cassian Menol Razeek


Oracle Trunc Function

2008-11-24

Among various helpful functions provided by Oracle, Trunc function took my attention today because I had to fix a defect where some one has misunderstood and misused this function.

As the name itself suggests, the trunc function is capable of truncating a value. This function can be used either on a date type value or a numeric value.

Using trunc for numeric values

When it comes to numbers, trunc function can return a number truncated to a certain number of decimal places.

syntax:

trunc( number, [ decimal_places ] )

Example usage:

trunc(125.815) would return 125
trunc(125.815, 0) would return 125
trunc(125.815, 1) would return 125.8
trunc(125.815, 2) would return 125.81
trunc(125.815, 3) would return 125.815
trunc(-125.815, 2) would return -125.81
trunc(125.815, -1) would return 120
trunc(125.815, -2) would return 100
trunc(125.815, -3) would return 0

Menol

Note: The trunc function does not round the values like in round function. It simply truncates the number as instructed.

Using trunc for date values

The trunc function is capable to truncate a date value to a specific unit of measure.

Syntax:

trunc ( date, [ format ] )

Possible values for format parameter:

Unit Valid format parameters
Year SYYYY, YYYY, YEAR, SYEAR, YYY, YY, Y
ISO Year IYYY, IY, I
Quarter Q
Month MONTH, MON, MM, RM
Week WW
IW IW
W W
Day DDD, DD, J
Start day of the week DAY, DY, D
Hour HH, HH12, HH24
Minute MI

Menol

Example Usage:

trunc(to_date(’22-AUG-03′), ‘YEAR’) would return ’01-JAN-03′
trunc(to_date(’22-AUG-03′), ‘Q’) would return ’01-JUL-03′
trunc(to_date(’22-AUG-03′), ‘MONTH’) would return ’01-AUG-03′
trunc(to_date(’22-AUG-03′), ‘DDD’) would return ’22-AUG-03′
trunc(to_date(’22-AUG-03′), ‘DAY’) would return ’17-AUG-03′

Menol

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

Cassian Menol Razeek


  • Visitors Since Oct, 2008
  • Protected By Copyscape Duplicate Content Checker
    Do Not Copy Without Referencing To This Site
  • Copyright © 1996-2010 I Learnt Today.... All rights reserved.
    iDream theme by Templates Next | Powered by WordPress