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

Initialize the DatePicker to a Value

1 Answer 167 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
Gerry
Top achievements
Rank 1
Gerry asked on 30 Oct 2009, 08:09 AM

I use a RadDatePicker inside a DataTemplate and assign it to the CellEditTemplate of a column of a RadGridView. When I do this, the RadDatePicker does not pick up the value of the current cell (or of the datasource collection behind it), but it is initialized to nothing. So I tried to set the initial value of the datepicker programmatically. You see my attempt in the code below. But it does not work. Can you give me a way to set an initial value in the RadDatePicker control.

XAML
=====
        <Grid.Resources>
            <DataTemplate x:Key="UIDatePicker">
                <input:RadDatePicker x:Name="UIRadDatePicker" SelectionChanged="UIRadDatePicker_SelectionChanged"   Loaded="UIRadDatePicker_Loaded"/>
            </DataTemplate>
        </Grid.Resources>

Code
====
// I have the value in rowrec.fodWert and would like to initalize the DatePicker to this value.

        private void UIRadGridFormular_CurrentCellChanged(object sender, GridViewCurrentCellChangedEventArgs evt)
        {
         GridViewCell newCell = evt.NewCell;
         RecFormulare rowrec = (RecFormulare)rowItem.DataContext;

         DataTemplate templa = LayoutRoot.Resources["UIDatePicker"] as DataTemplate;
         ((GridViewDataColumn)this.UIRadGridFormular.Columns["UIWert"]).CellEditTemplate = templa;

                RadDatePicker rdp = LayoutRoot.Resources["UIRadDatePicker"] as RadDatePicker;
                DateTime dt;
                bool ok = DateTime.TryParse(rowrec.fodWert, out dt);
                if (ok)
                {
                    if (rdp != null)
                    {
                         rdp.DisplayDate = dt; // Does not work
                    }
                    newCell.Value = dt; // Does not work
                }

1 Answer, 1 is accepted

Sort by
0
Gerry
Top achievements
Rank 1
answered on 30 Oct 2009, 08:44 AM
Sorry I found the problem. I need to set RadDatePicker.SelectedDate.
Tags
DatePicker
Asked by
Gerry
Top achievements
Rank 1
Answers by
Gerry
Top achievements
Rank 1
Share this question
or