DataFormatString Editor

5 posts, 0 answers
  1. MiddleTommy
    MiddleTommy avatar
    163 posts
    Member since:
    Nov 2009

    Posted 05 Oct 2010 Link to this post

    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.



  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 05 Oct 2010 Link to this post

    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
  3. DevCraft banner
  4. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 01 May 2013 Link to this post

    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

  5. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 07 May 2013 Link to this post

    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.

  6. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 07 May 2013 Link to this post

    This is the exact right answer.  Thank you again !
Back to Top
DevCraft banner