Hi guys
I’m using RadDomainDataSource, RadGridView and System.Windows.Controls.Data.DataForm (RadDataForm does not meet requirements)
<
telerik:RadDomainDataSource
Name
=
"OrganizerDomainDataSource"
AutoLoad
=
"False"
Height
=
"0"
Width
=
"0"
DomainContext
=
"{StaticResource OrganizerDomainContext}"
QueryName
=
"GetLocationSetQuery"
PageSize
=
"1000"
>
</
telerik:RadDomainDataSource
>
<
telerik:RadGridView
Name
=
"LocationDataGrid"
AutoGenerateColumns
=
"False"
Grid.Column
=
"0"
Grid.Row
=
"1"
HorizontalAlignment
=
"Stretch"
VerticalAlignment
=
"Stretch"
ItemsSource
=
"{Binding Path=DataView, ElementName=OrganizerDomainDataSource}"
RowDetailsVisibilityMode
=
"VisibleWhenSelected"
RowIndicatorVisibility
=
"Collapsed"
AlternationCount
=
"2"
IsEnabled
=
"{Binding Path=Parent.HasChanges, ElementName=LayoutRoot, Converter={StaticResource NotOperatorValueConverter}}"
IsReadOnly
=
"True"
ShowGroupPanel
=
"False"
IsFilteringAllowed
=
"True"
SelectionMode
=
"Single"
SelectionUnit
=
"FullRow"
>
<
Controls:DataForm
x:Name
=
"LocationDataForm"
Grid.Column
=
"2"
Grid.Row
=
"1"
Header
=
"{Binding Path=DataForm_Header, Source={StaticResource GlobalResources}}"
HorizontalAlignment
=
"Stretch"
VerticalAlignment
=
"Stretch"
ItemsSource
=
"{Binding Path=DataView, ElementName=OrganizerDomainDataSource}"
CurrentItem
=
"{Binding Path=SelectedItem, ElementName=LocationDataGrid, Mode=OneWay}"
AutoGenerateFields
=
"true"
AutoCommit
=
"False"
AutoEdit
=
"False"
CommandButtonsVisibility
=
"Edit, Commit, Cancel"
CancelButtonContent
=
"{Binding Path=CancelButton, Source={StaticResource GlobalResources}}"
CommitButtonContent
=
"{Binding Path=CommitButton, Source={StaticResource GlobalResources}}"
BeginningEdit
=
"LocationDataForm_BeginningEdit"
EditEnded
=
"LocationDataForm_EditEnded"
ContentLoaded
=
"LocationDataForm_ContentLoaded"
>
</
Controls:DataForm
>
This combination of controls is working fine in most cases but when LocationDataGrid has no items and I try to create new item with:
private void NewLocationButton_Click(object sender, RoutedEventArgs e)
{
LocationDataForm.AddNewItem();
var newItem = LocationDataForm.CurrentItem as Location;
if (newItem != null)
{
// force to switch in DataForm.IsEditing
newItem.UpdateDatetime = DateTime.Now;
}
}
One exception is thrown:
at System.Windows.Controls.DataForm.GetAllOriginalPropertyValues()
at System.Windows.Controls.DataForm.AddNewItem()
at T2LOrganizer.Views.Samples.SamplePage.NewLocationButton_Click(Object sender, RoutedEventArgs e)
at System.Windows.Controls.Primitives.ButtonBase.OnClick()
at System.Windows.Controls.Button.OnClick()
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)
Exception is not in Telerik control and I thought it has nothing to do with you guys but when I replace RadDomainDataSource and RadGridView with Silverlight base controls this is not happening.
If I slightly modify Binding options to:
<
Controls:DataForm
x:Name
=
"LocationDataForm"
Grid.Column
=
"2"
Grid.Row
=
"1"
Header
=
"{Binding Path=DataForm_Header, Source={StaticResource GlobalResources}}"
HorizontalAlignment
=
"Stretch"
VerticalAlignment
=
"Stretch"
ItemsSource
=
"{Binding Path=Items, ElementName=LocationDataGrid}"
CurrentItem
=
"{Binding Path=SelectedItem, ElementName=LocationDataGrid, Mode=OneWay}"
AutoGenerateFields
=
"true"
AutoCommit
=
"False"
AutoEdit
=
"False"
CommandButtonsVisibility
=
"Edit, Commit, Cancel"
CancelButtonContent
=
"{Binding Path=CancelButton, Source={StaticResource GlobalResources}}"
CommitButtonContent
=
"{Binding Path=CommitButton, Source={StaticResource GlobalResources}}"
BeginningEdit
=
"LocationDataForm_BeginningEdit"
EditEnded
=
"LocationDataForm_EditEnded"
ContentLoaded
=
"LocationDataForm_ContentLoaded"
>
</
Controls:DataForm
>
And code for creating new item:
private void NewLocationButton_Click(object sender, RoutedEventArgs e)
{
var createdItem = LocationDataGrid.Items.AddNew();
LocationDataGrid.SelectedItem = createdItem;
var newItem = LocationDataForm.CurrentItem as Location;
if (newItem != null)
{
// force to switch in DataForm.IsEditing
newItem.UpdateDatetime = DateTime.Now;
}
}
Problem disappears but I’m not sure about side effects (seems to me that re-loading after new item is saved takes a bit more time than before changes)
Any suggestion how to manage binding between RadDomainDataSource, RadGridView and Dataform in a proper way?
Thanks in advance!
Dejan