FormatString for Editors in GridView

7 posts, 0 answers
  1. Rachel
    Rachel avatar
    37 posts
    Member since:
    Mar 2008

    Posted 15 Sep 2009 Link to this post

    Hello,
    I use formatstrings to format the data in the columns of my gridview, but when the user begins to edit a cell, the formatstring is not applied.  This means sometimes many zeros can show, effectively filling the editor with zeros and making editing cumbersome.  Is there a way to apply a formatstring to what is shown in the editor?

    Thanks in advance!
    Rachel
  2. Stefan Dobrev
    Admin
    Stefan Dobrev avatar
    790 posts

    Posted 17 Sep 2009 Link to this post

    Hello Rachel,

    We currently did not support this scenario by default. However you can create a CellEditTemplate to handle this. Here is an example GridViewDataColumn with custom edit template that handles your case:
    <telerik:GridViewDataColumn Header="Number" DataMemberBinding="{Binding Number}" DataFormatString="{}{0:000}"
        <telerik:GridViewDataColumn.CellEditTemplate> 
            <DataTemplate> 
                <TextBox Text="{Binding Number, Converter={StaticResource StringFormatter}, ConverterParameter='{0:000}'}"  /> 
            </DataTemplate> 
        </telerik:GridViewDataColumn.CellEditTemplate> 
    </telerik:GridViewDataColumn> 

    I'm attaching the sample project for your reference.

    Hope this helps.

    Sincerely yours,
    Stefan Dobrev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. DevCraft banner
  4. Celeste
    Celeste avatar
    34 posts
    Member since:
    May 2009

    Posted 05 Nov 2009 Link to this post

    I downloaded your example but after I edit a cell and when it lost focus, I can see old value. Is binding working?


  5. Stefan Dobrev
    Admin
    Stefan Dobrev avatar
    790 posts

    Posted 09 Nov 2009 Link to this post

    Hello Celeste,

    You should set the the mode of the binding to TwoWay in order to get the updated value back into the grid. Please note that you should implement the convert back method of the StringFormatConverter.

    Greetings,
    Stefan Dobrev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  6. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 01 May 2013 Link to this post

    How do I achieve this with date that should be MM-dd-YYYY when the user select English and dd-MM-yyyy when the user selected French at runtime ?
  7. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 06 May 2013 Link to this post

    Hello,

    This formatting is language specific and it will be changed once you set another Language for the GridView. For example:

    this.clubsGrid.Language =  XmlLanguage.GetLanguage("en");

    Regards,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

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

    Posted 06 May 2013 Link to this post

    That's exactly what I found and it works all right.  Thank you
Back to Top
DevCraft banner