We are using Telerik Q1 2011 build 0322 (tested with 0328 too).
There 2 problems when using grid + RadDomainDataSource.
1. Need an ability to insert prepared object into domain data source and submit changes.
When trying to RadDomainDataSource.DataView.Add(new MyObject());
getting an exception:
System.InvalidOperationException was unhandled by user code
Message=Operation is not valid while ItemsSource is in use. Access and modify elements with ItemsControl.ItemsSource instead.
StackTrace:
at Telerik.Windows.Data.DataItemCollection.EnsureIsUsingInternalView()
at Telerik.Windows.Data.DataItemCollection.Add(Object value)
at Accellos.DataServices.WUI.FileMaintenance.Controls.Test1.MyWorkspaceControl1.<.ctor>b__2(Object , RoutedEventArgs )
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)
InnerException:
Is there any other way to insert object into RadDomainDataSource and submit changes ?
2. After inserting a new row (hit "Insert" key) an submitting changes grid selection is totally screwed when selecting with mouse.
http://img600.imageshack.us/i/gridv.png
Here's the source code:
<
UserControl
x:Class
=
"Accellos.DataServices.WUI.FileMaintenance.Controls.Test1.MyWorkspaceControl1"
xmlns:mt
=
"clr-namespace:Accellos.DataServices.MT.Client.SL.DomainDataSource.Context;assembly=Accellos.DataServices.MT.Client.DataServicesAsync.SL"
xmlns:radData
=
"clr-namespace:Telerik.Windows.Data;assembly=Telerik.Windows.Data"
xmlns:radDomain
=
"clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.DomainServices"
xmlns:radGrid
=
"clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"
xmlns:Controls
=
"clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Data"
>
<
UserControl.Resources
>
<
radDomain:RadDomainDataSource
x:FieldModifier
=
"public"
x:Name
=
"BuildingTypeDomainDataSource"
QueryName
=
"FindAllBuildingType"
AutoLoad
=
"True"
DataContext
=
"{Binding}"
>
<
radDomain:RadDomainDataSource.DomainContext
>
<
mt:BuildingTypeDomainContext
/>
</
radDomain:RadDomainDataSource.DomainContext
>
<
radDomain:RadDomainDataSource.QueryParameters
>
<
radDomain:QueryParameter
ParameterName
=
"BuildingTypeHydration"
Value
=
"None"
/>
</
radDomain:RadDomainDataSource.QueryParameters
>
<
radDomain:RadDomainDataSource.SortDescriptors
>
<
radData:SortDescriptor
Member
=
"Type"
SortDirection
=
"Ascending"
/>
</
radDomain:RadDomainDataSource.SortDescriptors
>
</
radDomain:RadDomainDataSource
>
</
UserControl.Resources
>
<
Grid
>
<
Grid.RowDefinitions
>
<
RowDefinition
Height
=
"Auto"
/>
<
RowDefinition
Height
=
"*"
/>
<
RowDefinition
Height
=
"Auto"
/>
</
Grid.RowDefinitions
>
<
Grid.ColumnDefinitions
>
<
ColumnDefinition
Width
=
"*"
/>
</
Grid.ColumnDefinitions
>
<
Button
x:Name
=
"InsertButton"
Content
=
"Insert new row"
/>
<
radGrid:RadGridView
Grid.Row
=
"1"
x:Name
=
"gridView1"
AutoGenerateColumns
=
"False"
SelectionMode
=
"Extended"
IsSynchronizedWithCurrentItem
=
"True"
ItemsSource
=
"{Binding DataView, Source={StaticResource BuildingTypeDomainDataSource}}"
>
<
radGrid:RadGridView.Columns
>
<
radGrid:GridViewDataColumn
UniqueName
=
"Id"
DataMemberBinding
=
"{Binding Path=Id, Mode=TwoWay}"
IsReadOnly
=
"True"
IsGroupable
=
"True"
Width
=
"Auto"
IsVisible
=
"True"
>
<
radGrid:GridViewDataColumn.Header
>
<
TextBlock
Text
=
"Id"
ToolTipService.ToolTip
=
"Id"
/>
</
radGrid:GridViewDataColumn.Header
>
</
radGrid:GridViewDataColumn
>
<
radGrid:GridViewDataColumn
UniqueName
=
"Type"
DataMemberBinding
=
"{Binding Path=Type, Mode=TwoWay}"
IsReadOnly
=
"False"
IsGroupable
=
"True"
Width
=
"Auto"
IsVisible
=
"True"
>
<
radGrid:GridViewDataColumn.Header
>
<
TextBlock
Text
=
"Type"
ToolTipService.ToolTip
=
"Type"
/>
</
radGrid:GridViewDataColumn.Header
>
</
radGrid:GridViewDataColumn
>
</
radGrid:RadGridView.Columns
>
</
radGrid:RadGridView
>
<
Controls:RadDataPager
Grid.Row
=
"2"
Name
=
"dataPager1"
PageSize
=
"20"
Source
=
"{Binding DataView, Source={StaticResource BuildingTypeDomainDataSource}}"
/>
</
Grid
>
</
UserControl
>
public
MyWorkspaceControl1()
{
InitializeComponent();
gridView1.RowEditEnded +=
delegate
(
object
o, GridViewRowEditEndedEventArgs e)
{
if
(e.EditAction != GridViewEditAction.Commit)
{
BuildingTypeDomainDataSource.RejectChanges();
return
;
}
if
(BuildingTypeDomainDataSource.HasChanges && !BuildingTypeDomainDataSource.IsSubmittingChanges)
BuildingTypeDomainDataSource.SubmitChanges();
};
gridView1.Deleted +=
delegate
{
if
(BuildingTypeDomainDataSource.HasChanges && !BuildingTypeDomainDataSource.IsSubmittingChanges)
BuildingTypeDomainDataSource.SubmitChanges();
};
InsertButton.Click +=
delegate
{
BuildingTypeDomainDataSource.DataView.Add(
new
BuildingType());
};
}