What is the best way to set the edit date format in autogenerated column

5 posts, 0 answers
  1. Stew
    Stew avatar
    1 posts
    Member since:
    Feb 2012

    Posted 28 Feb 2012 Link to this post

    Hi,

    I have am using autogenerated columns in a gridview, and I don't want to manually generate them.

    What is the most painless way to get the column, when editing or inserting a date, to put the datepicker into DateSelectionMode=Month, and display the date as month/year.

    I am already hooking the AutoGenerateColumns event to add aggregate functions on some columns, so I can add more here if necessary.

    current grid style:
    <Style TargetType="telerik:RadGridView" x:Name="Grid">
                <Setter Property="ShowGroupPanel" Value="False" />
                <Setter Property="CanUserInsertRows" Value="True" />
                <Setter Property="ShowColumnFooters" Value="True" />
                <Setter Property="ShowInsertRow" Value="True" />
                <Setter Property="CanUserDeleteRows" Value="True" />
                <Setter Property="SelectionMode" Value="Single"  />
                <Setter Property="RowIndicatorVisibility" Value="Collapsed" />            
                <Setter Property="AutoGenerateColumns" Value="True"/>   
                <Setter Property="telerik:RadDateTimePicker.DateSelectionMode" Value="Month"/> <!--this doesn't seem to have any effect-->              
            </Style>
    Grid definition:
    <telerik:RadGridView Grid.Row="1" ItemsSource="{Binding Items}" Style ="{StaticResource Grid}"
                                         AutoGeneratingColumn="RadGridViewAutoGeneratingColumn" >                    
                    </telerik:RadGridView>
    Item definition:

    public class Item : NotificationObject
        {
            private DateTime _date = new DateTime(DateTime.Now.Year, DateTime.Now.Month,1); //default to this month
            [Display(Name = "Recovery Date")]
            [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/yyyy}")]
            public DateTime Date
            {
                get { return _date; }
                set
                {
                    if (_date != value)
                    {
                        _date = value;
                        RaisePropertyChanged(() => Date);
                    }
                }
            }
        }

    Thanks for your help,

    Stew
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 29 Feb 2012 Link to this post

    Hello Stew,

    You can try defining DataFormatString property of your column in AutoGeneratingColumn event. As for setting any of the properties of RadDateTimePicker, you need to add style targeting it, not RadGridView.

    All the best,
    Maya
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. DevCraft banner
  4. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 01 May 2013 Link to this post

    What if I have AutoGenerateColumns to false and I need to change the Date format at runtime ?
  5. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 01 May 2013 Link to this post

    Hello Mark,

    You can find the required column in the Columns collection of the grid and set DataFormatString to it.  

    Kind regards,
    Maya
    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 02 May 2013 Link to this post

    gotcha.  Thanx
Back to Top
DevCraft banner