Here is my Xaml:
<telerik:RadGridView x:Name=
"rgvMainGrid"
Width=
"1088"
MaxWidth=
"1088"
Margin=
"5"
HorizontalAlignment=
"Left"
AutoGenerateColumns=
"False"
CanUserDeleteRows=
"False"
CanUserInsertRows=
"False"
IsReadOnly=
"True"
ScrollViewer.VerticalScrollBarVisibility=
"Auto"
RowLoaded=
"rgvMainGrid_RowLoaded"
>
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn Width=
"160"
DataMemberBinding=
"{Binding StartTime}"
EditTriggers=
"CellClick"
Header=
"Start Time"
>
<telerik:GridViewDataColumn.CellEditTemplate>
<DataTemplate>
<telerik:RadDateTimePicker x:Name=
"rdpStartTimePicker"
SelectedValue="{Binding StartTime,
Mode=TwoWay}" />
</DataTemplate>
</telerik:GridViewDataColumn.CellEditTemplate>
</telerik:GridViewDataColumn>
<telerik:GridViewDataColumn Width=
"160"
DataMemberBinding=
"{Binding EndTime}"
EditTriggers=
"CellClick"
Header=
"End Time"
>
<telerik:GridViewDataColumn.CellEditTemplate>
<DataTemplate>
<telerik:RadDateTimePicker x:Name=
"rdpEndTimePicker"
SelectedValue="{Binding EndTime,
Mode=TwoWay}" />
</DataTemplate>
</telerik:GridViewDataColumn.CellEditTemplate>
</telerik:GridViewDataColumn>
<telerik:GridViewDataColumn Width=
"*"
DataMemberBinding=
"{Binding Notes}"
Header=
"Notes"
TextWrapping=
"Wrap"
/>
</telerik:RadGridView.Columns>
</telerik:RadGridView>
Here is my code behind:
private
void
rgvMainGrid_RowLoaded(
object
sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e)
{
var _Picker = e.Row.FindName(
"rdpStartTimePicker"
)
as
RadDateTimePicker;
if
(_Picker !=
null
)
{
if
(rdpDate.SelectedDate !=
null
)
{
_Picker.SelectableDateStart = rdpDate.SelectedDate;
_Picker.SelectableDateEnd = rdpDate.SelectedDate.Value.AddDays(1);
}
}
}
Am I close? I tried looking through everything under e and e.Row but I couldn't find where rdpStartTimePicker is mentioned.
13 Answers, 1 is accepted
I would recommend you to count on Bindings instead - you can expose properties to bind to SelectableDateStart and SelectableDateEnd.
Nevertheless, I would recommend you to use ChildrenOfType<T>()/ ParentOfType<T>() extension methods rather than FindName.
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
You can find a control in a cell with the help of ChildrenOfType<T>() extension method. In you case it will be ChildrenOfType<RadDateTimePicker>() - once you find the one you want, you can set date pattern.
As for clicking on the calendar icon - what is the exact behavior that you want to achieve, do you define date time picker in CellTemplate or CellEditTemplate, do you want just to display the values without being able to open the drop down of the picker ?
Maya
Telerik
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
With the following code, when we want to change the date by using the picker icon, it doesn't change the value even thought the mode is TwoWay. The need is to have the Editor readonly HOWEVER, we should be able to change the date using the picker
Maybe a IsEditorReadonly would have been great.
<
telerik:GridViewDataColumn
Header
=
"Date du compte"
UniqueName
=
"AccountDate"
DataFormatString
=
"{}{0:MMM-yyyy}"
>
<
telerik:GridViewDataColumn.CellEditTemplate
>
<
DataTemplate
>
<
telerik:RadDatePicker
DateSelectionMode
=
"Month"
SelectedValue
=
"{Binding AccountDate, Mode=TwoWay}"
IsReadOnly
=
"True"
></
telerik:RadDatePicker
>
</
DataTemplate
>
</
telerik:GridViewDataColumn.CellEditTemplate
>
</
telerik:GridViewDataColumn
>
I might be missing the point here, but if you want the property to be updated and see it in read-only mode of the column, you need to bind it (set DataMemberBinding).
Maya
Telerik
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
<
telerik:GridViewDataColumn
Header
=
"Date du compte"
UniqueName
=
"AccountDate"
DataFormatString
=
"{}{0:MMM-yyyy}"
DataMemberBinding
=
"{Binding AccountDate, Mode=TwoWay}"
>
<
telerik:GridViewDataColumn.CellEditTemplate
>
<
DataTemplate
>
<
telerik:RadDatePicker
DateSelectionMode
=
"Month"
SelectedValue
=
"{Binding AccountDate, Mode=TwoWay}"
IsReadOnly
=
"True"
></
telerik:RadDatePicker
>
</
DataTemplate
>
</
telerik:GridViewDataColumn.CellEditTemplate
>
</
telerik:GridViewDataColumn
>
Indeed, I missed something in your requirements - do you want to be able to select date from the drop down, but not to edit the TextBox ?
Maya
Telerik
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
The way to go is to handle Loaded event, find the TextBox and set IsReadOnly only to it:
<
telerik:GridViewDataColumn
Header
=
"Date du compte"
UniqueName
=
"AccountDate"
DataFormatString
=
"{}{0:MMM-yyyy}"
DataMemberBinding
=
"{Binding Established, Mode=TwoWay}"
>
<
telerik:GridViewDataColumn.CellEditTemplate
>
<
DataTemplate
>
<
telerik:RadDatePicker
DateSelectionMode
=
"Month"
SelectedValue
=
"{Binding Established, Mode=TwoWay}"
Loaded
=
"RadDatePicker_Loaded"
>
</
telerik:RadDatePicker
>
</
DataTemplate
>
</
telerik:GridViewDataColumn.CellEditTemplate
>
</
telerik:GridViewDataColumn
>
private void RadDatePicker_Loaded(object sender, RoutedEventArgs e)
{
var picker = sender as RadDateTimePicker;
var textBox = picker.ChildrenOfType<
TextBox
>().FirstOrDefault();
if (textBox != null)
{
textBox.IsReadOnly = true;
}
}
Regards,
Maya
Telerik
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.