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

Remove Entity from RadDomainDataSource

3 Answers 93 Views
DomainDataSource
This is a migrated thread and some comments may be shown as answers.
Dejan
Top achievements
Rank 1
Dejan asked on 13 Oct 2011, 10:39 AM
Hi all

I want to implement custom deleting of Entity using RadDomainDataSource and RadGridView:
<telerik:RadDomainDataSource 
    Name="OrganizerDomainDataSource" 
    AutoLoad="False" Height="0"  Width="0"
    DomainContext="{StaticResource OrganizerDomainContext}"
    QueryName="GetLocationSetQuery" PageSize="1000"
    LoadedData="OrganizerDomainDataSource_LoadedData" 
    SubmittedChanges="OrganizerDomainDataSource_SubmittedChanges">
</telerik:RadDomainDataSource>

<telerik:RadGridView  
                Name="LocationDataGrid" 
                AutoGenerateColumns="False" 
                Grid.Row="1" Grid.Column="0" 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">
                <telerik:RadGridView.Columns>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=Name}" 
                                                                            TextAlignment="Left" HeaderTextAlignment="Left"  
                                                                            Header="{Binding Path=LocationPage_LocationDataGrid_Header_Name, Source={StaticResource PageResources}}"  
                                                                            Width="SizeToCells"
                                                                            IsFilterable="True"
                                                                            ShowDistinctFilters="False"
                                                                            ShowFieldFilters="True"/>
  
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=City}" 
                                                                            Header="{Binding Path=LocationPage_LocationDataGrid_Header_City, Source={StaticResource PageResources}}" 
                                                                            Width="SizeToCells"
                                                                            IsFilterable="True"
                                                                            ShowDistinctFilters="False"
                                                                            ShowFieldFilters="True"/>
  
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=OrganisationPath}" 
                                                                            Header="{Binding Path=LocationPage_LocationDataGrid_Header_CompanyPath, Source={StaticResource PageResources}}"  
                                                                            Width="*"
                                                                            IsFilterable="True"
                                                                            ShowDistinctFilters="False"
                                                                            ShowFieldFilters="True"/>
  
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=RoomSet.Count}" 
                                                                            TextAlignment="Right" HeaderTextAlignment="Right" 
                                                                            Header="{Binding Path=LocationPage_LocationDataGrid_Header_RoomNumber, Source={StaticResource PageResources}}"  
                                                                            Width="SizeToHeader"
                                                                            IsFilterable="True"
                                                                            ShowDistinctFilters="False"
                                                                            ShowFieldFilters="True"/>
  
                    <telerik:GridViewDataColumn 
                        x:Name="functionColumn" 
                        Header="{Binding Path=LocationPage_LocationDataGrid_Header_Functions, Source={StaticResource PageResources}}" Width="SizeToHeader">
                        <telerik:GridViewDataColumn.CellTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <Button Style="{StaticResource ImageButtonStyle}" Click="DeleteItemButton_Click" CommandParameter="{Binding Path=LocationId}">
                                        <Image Source="../../Assets/Images/Icons/btn_delete.png"/>
                                        <ToolTipService.ToolTip>
                                            <ToolTip Content="{Binding Path=LocationPage_LocationDataGrid_Function_Tooltip_Delete, Source={StaticResource PageResources}}"></ToolTip>
                                        </ToolTipService.ToolTip>
                                    </Button>
                                </StackPanel>
                            </DataTemplate>
                        </telerik:GridViewDataColumn.CellTemplate>
                    </telerik:GridViewDataColumn>
                </telerik:RadGridView.Columns>
            </telerik:RadGridView>

In code behind I implemented DeleteButton handler:


/// <summary>
/// delete selected location
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void DeleteItemButton_Click(object sender, RoutedEventArgs e)
{
    var itemId = (Guid)((Button)sender).CommandParameter;
    var location = GetLocationFromDataSource(itemId);
    if (location != null)
    {
        // ClxMessageBox: are you sure?
        var msgBoxDeleting = new ClxMessageBox(ClxMessageBoxType.YesNo)
        {
            Title = GlobalResources.MsgBoxDeleting_Title,
            Message = string.Format(GlobalResources.MsgBoxDeleting_Message, location.Name + "(" + location.OrganisationPath + ")")
        };
        msgBoxDeleting.ShowDialog(result =>
        {
            if (result)
            {
                LocationDataGrid.Items.Remove(location);
                OrganizerDomainDataSource.SubmitChanges();
            }
        });
    }
}

I did not find a way to remove selected Location directly from OrganizerDomainDataSource so I removed it from LocationDataGrid.

This implementation actually works.

 

Only question is: is there a better solution for removing Entity from RadDomainDataSource then this one:

 

LocationDataGrid.Items.Remove(location);
OrganizerDomainDataSource.SubmitChanges();

Regards,
Dekos

 

3 Answers, 1 is accepted

Sort by
0
Accepted
Rossen Hristov
Telerik team
answered on 13 Oct 2011, 11:03 AM
Hello Dejan,

Can you try this:

this.radDomainDataSource.DataView.Remove(item); // there is RemoveAt(index) as well
this.radDomainDataSource.SubmitChanges();

Greetings,

Ross
the Telerik team

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

0
Dejan
Top achievements
Rank 1
answered on 13 Oct 2011, 11:14 AM
Thanks Ross!

Reading other threads at forum (e.g. http://www.telerik.com/community/forums/silverlight/gridview/2-problems-with-grid-raddomaindatasource.aspx ) I realized that messing around with DataView directly can make some thoubles.
 
Anyway your proposal is working in this scenario.
Your are not aware of any side efects in using it?

Regards,
Dejan
0
Rossen Hristov
Telerik team
answered on 13 Oct 2011, 11:16 AM
Hi Dejan,

It will be fine. When you remove an item from the grid, you will reach the same code eventually, so it's fine.

Best wishes,
Ross
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
Rossen Hristov
Telerik team
Dejan
Top achievements
Rank 1
Share this question
or