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

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

4 Answers 153 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Stew
Top achievements
Rank 1
Stew asked on 28 Feb 2012, 09:58 PM
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

4 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 29 Feb 2012, 07:57 AM
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 >>
0
Marc Roussel
Top achievements
Rank 2
answered on 01 May 2013, 02:06 PM
What if I have AutoGenerateColumns to false and I need to change the Date format at runtime ?
0
Maya
Telerik team
answered on 01 May 2013, 09:02 PM
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.

0
Marc Roussel
Top achievements
Rank 2
answered on 02 May 2013, 11:20 AM
gotcha.  Thanx
Tags
GridView
Asked by
Stew
Top achievements
Rank 1
Answers by
Maya
Telerik team
Marc Roussel
Top achievements
Rank 2
Share this question
or