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

exception when using empty DomainDataSource

1 Answer 51 Views
DomainDataSource
This is a migrated thread and some comments may be shown as answers.
Dejan
Top achievements
Rank 1
Dejan asked on 14 Oct 2011, 11:00 AM

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


 

1 Answer, 1 is accepted

Sort by
0
Nedyalko Nikolov
Telerik team
answered on 19 Oct 2011, 09:58 AM
Hello Dejan,

Generally RadDomainDataSource control has a built-in integration with RadGridView, so adding new items via RadGridView.Items collection looks like a proper approach. Unfortunately I cannot say nothing about the re-load delay without a sample project (everything looks OK).

To summarize the modified approach is the better one (not only because there is no exception).

All the best,
Nedyalko Nikolov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
DomainDataSource
Asked by
Dejan
Top achievements
Rank 1
Answers by
Nedyalko Nikolov
Telerik team
Share this question
or