This is a migrated thread and some comments may be shown as answers.

DataFormatString Editor

4 Answers 93 Views
GridView
This is a migrated thread and some comments may be shown as answers.
MiddleTommy
Top achievements
Rank 1
MiddleTommy asked on 05 Oct 2010, 05:14 AM
It seems if I have a 
<t:GridViewDataColumn DataMemberBinding="{Binding totalcost}"
                                              DataFormatString="{}{0:C2}"
                                              Header="total"/>
the data format string is not carried over to the editor.
Most importantly in this situation the number of decimal places.

the cell value could be 5.24
but when you go into edit mode the value turns into 5.23987852142

I guess this could be solved with a value converter on the binding.
I sure wish the DataColumn would transfer the DataFormatString to the editor Binding.
To do this you could have a Generic Converter on the binding if one is not supplied that set the formatstring as a converter parameter.
On second thought I guess I could just make a new base GridViewDataColumn for my use.



4 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 05 Oct 2010, 07:20 AM
Hello MiddleTommy,

 Generally DataFormatString is used only for view purposes - not for editing.  If you want to apply the same for your editor you can do this in CellEditTemplate directly to your editor Binding StringFormat property.

Sincerely yours,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Marc Roussel
Top achievements
Rank 2
answered on 01 May 2013, 10:37 PM
What ?
I don't understand.

We need to have visual DataFormaString change as well as the editing format at runtime because the user can change the language and we need to change the Editing format as well.  For us it's not decimal but date

0
Dimitrina
Telerik team
answered on 07 May 2013, 09:02 AM
Hello,

I will post the answer we gave in your support thread:

You may try to handle PreparingCellForEdit/PreparedCellForEdit events of RadGridView from where you may access the corresponding Editing Element.
Once you get the RadDateTimePicker instance you can set the date format by changing the Culture property, something like the following:

private void clubsGrid_PreparingCellForEdit(object sender, GridViewPreparingCellForEditEventArgs e)
{
        if ((string) e.Column.Header == "Date")
        {
                var rdt = e.EditingElement as RadDateTimePicker;
                rdt.Culture = new CultureInfo("en-US")
               {
                     DateTimeFormat = new DateTimeFormatInfo
               {
                     ShortDatePattern = "dd-MMM-yyyy"
                }
        };
 }
}

Greetings,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Marc Roussel
Top achievements
Rank 2
answered on 07 May 2013, 09:54 AM
This is the exact right answer.  Thank you again !
Tags
GridView
Asked by
MiddleTommy
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Marc Roussel
Top achievements
Rank 2
Dimitrina
Telerik team
Share this question
or