This question is locked. New answers and comments are not allowed.
Hi telerik ,
I have one strange problem I am trying to drop grid view data in another grid view , first of all I did not find any suitable example where you bound grid with RIA domain data source and we can check it.
Right now what happening with me I was not able to refresh second grid after drop , or you can say this line of code is not working for me
xxTable1DataSource.Clear();
xxTable1DataSource.Load();
I really appreciate if you can help me about drag and drop using wcf ria datasource , please find the example code here I used.
Thanks,
Shakti
<telerik:RadWindow xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" xmlns:riaControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.DomainServices" xmlns:my="clr-namespace:SilverFinancials.Web.Models" xmlns:my1="clr-namespace:SilverFinancials.Web.Services" xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit" x:Class="SilverFinancials.Windows.DragExample" mc:Ignorable="d" Closed="RadWindow_Closed" Header="Drag Example" Width="787" Height="385" d:DesignHeight="287" d:DesignWidth="400"> <Grid x:Name="LayoutRoot" Background="Gainsboro"> <Grid.RowDefinitions> <RowDefinition Height="0.9*"/> <RowDefinition Height="0.1*"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="0.446*"/> <ColumnDefinition Width="0.554*"/> </Grid.ColumnDefinitions> <riaControls:DomainDataSource AutoLoad="True" Height="0" LoadingData="billTypeDomainDataSource_LoadingData" LoadedData="billTypeDomainDataSource_LoadedData" x:Name="xxTable1DataSource" QueryName="GetXxTable1Query" Width="0" Grid.Column="1" Margin="10,10,10,10" > <riaControls:DomainDataSource.DomainContext> <my1:xxTable1 /> </riaControls:DomainDataSource.DomainContext> </riaControls:DomainDataSource> <riaControls:DomainDataSource AutoLoad="True" Height="0" LoadingData="billTypeDomainDataSource_LoadingData" LoadedData="billTypeDomainDataSource_LoadedData" x:Name="xxTable2DataSource" QueryName="GetXxTable2Query" Width="0" Grid.Column="1" Margin="10,10,10,10" > <riaControls:DomainDataSource.DomainContext> <my1:xxTable2 /> </riaControls:DomainDataSource.DomainContext> </riaControls:DomainDataSource> <telerik:RadGridView x:Name="billTypeRadGridView" ItemsSource="{Binding Data, ElementName=xxTable1DataSource}" AutoGenerateColumns="False" Background="Gainsboro" CanUserDeleteRows="False" CanUserInsertRows="True" Height="200" IsSynchronizedWithCurrentItem="false" CanUserFreezeColumns="False" CanUserReorderColumns="False" ShowGroupPanel="False" Grid.Row="0" Grid.Column="0" IsReadOnly="True" telerik:RadDragAndDropManager.AllowDrop="True" SelectionMode="Extended"> <telerik:RadGridView.RowStyle> <Style TargetType="telerik:GridViewRow"> <Setter Property="telerik:RadDragAndDropManager.AllowDrag" Value="True" /> </Style> </telerik:RadGridView.RowStyle> <telerik:RadGridView.Columns> <telerik:GridViewDataColumn DataMemberBinding="{Binding Description}" Header="Description"/> <telerik:GridViewDataColumn DataMemberBinding="{Binding Amount}" Header="Amount" IsReadOnly="True" /> </telerik:RadGridView.Columns> </telerik:RadGridView> <telerik:RadGridView x:Name="billTypeRadGridViewDrop" ItemsSource="{Binding Data, ElementName=xxTable2DataSource}" AutoGenerateColumns="False" Background="Gainsboro" CanUserDeleteRows="False" CanUserInsertRows="True" Height="200" IsSynchronizedWithCurrentItem="false" CanUserFreezeColumns="False" CanUserReorderColumns="False" ShowGroupPanel="False" Grid.Row="0" Grid.Column="1" IsReadOnly="True" telerik:RadDragAndDropManager.AllowDrop="True" SelectionMode="Extended"> <telerik:RadGridView.RowStyle> <Style TargetType="telerik:GridViewRow"> <Setter Property="telerik:RadDragAndDropManager.AllowDrag" Value="True" /> </Style> </telerik:RadGridView.RowStyle> <telerik:RadGridView.Columns> <telerik:GridViewDataColumn DataMemberBinding="{Binding Description}" Header="Description"/> <telerik:GridViewDataColumn DataMemberBinding="{Binding Amount}" Header="Amount" IsReadOnly="True" /> </telerik:RadGridView.Columns> </telerik:RadGridView> <telerik:RadButton Content="Save" HorizontalAlignment="Right" Click="saveRBTN_Click" Height="23" x:Name="saveRBTN" Width="75" Grid.Row="1" Grid.Column="1" /> <telerik:RadButton Content="Canel" HorizontalAlignment="Right" Height="23" x:Name="cancelRBTN" Click="cancelRBTN_Click" Width="75" Grid.Row="1" Grid.Column="1" /> </Grid></telerik:RadWindow>
using System.Windows;using System.Windows.Controls;using Telerik.Windows.Controls;using Telerik.Windows.Controls.DragDrop;using System.ServiceModel.DomainServices.Client;using System;using Telerik.Windows.Controls.GridView;using System.Collections.Generic;using System.Collections;using System.Collections.ObjectModel;using System.Linq;using Telerik.Windows.Controls.TreeView;using System.Windows.Media;using SilverFinancials.Web.Models;namespace SilverFinancials.Windows{ public partial class DragExample : RadWindow { #region private member private bool hasConcurrencyIssue = false; #endregion #region Constructor public DragExample() { try { InitializeComponent(); //xxTable2DataSource.DomainContext.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(DomainContext_PropertyChanged); } catch (Exception ex) { RadWindow.Alert("Screen timed out. Please open again!"); } //MyBusinessObjects businessObjectGenerator = new MyBusinessObjects(); //SilverFinancials.Web.Services.xxTable1 x = new SilverFinancials.Web.Services.xxTable1(); //EntityQuery<SilverFinancials.Web.Models.xxTable1> xx = x.GetXxTable1Query(); //foreach (SilverFinancials.Web.Models.xxTable1 sd in x.GetXxTable1Query()) //{ //} RadDragAndDropManager.AddDropQueryHandler(billTypeRadGridView, OnDropQuery); RadDragAndDropManager.AddDropInfoHandler(billTypeRadGridView, OnDropInfoxxTable2); RadDragAndDropManager.AddDragQueryHandler(billTypeRadGridView, OnDragQuery); RadDragAndDropManager.AddDragInfoHandler(billTypeRadGridView, OnDragInfoxxTable1); RadDragAndDropManager.AddDropQueryHandler(billTypeRadGridViewDrop, OnDropQuery); RadDragAndDropManager.AddDropInfoHandler(billTypeRadGridViewDrop, OnDropInfoxxTable1); RadDragAndDropManager.AddDragQueryHandler(billTypeRadGridViewDrop, OnDragQuery); RadDragAndDropManager.AddDragInfoHandler(billTypeRadGridViewDrop, OnDragInfoxxTable2); } private void DomainContext_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { //saveRBTN.IsEnabled = billTypeDomainDataSource.DomainContext.HasChanges; //cancelRBTN.IsEnabled = billTypeDomainDataSource.DomainContext.HasChanges; //xxTable2DataSource.Clear(); //xxTable2DataSource.Load(); } #endregion #region Load event handler for the domain data source private void billTypeDomainDataSource_LoadedData(object sender, LoadedDataEventArgs e) { if (e.HasError) { System.Windows.MessageBox.Show(e.Error.ToString(), "Load Error", System.Windows.MessageBoxButton.OK); e.MarkErrorAsHandled(); } } private void billTypeDomainDataSource_LoadingData(object sender, LoadingDataEventArgs e) { e.LoadBehavior = System.ServiceModel.DomainServices.Client.LoadBehavior.RefreshCurrent; } #endregion #region Save/Cancel button event handlers private void saveRBTN_Click(object sender, RoutedEventArgs e) { //saveRBTN.IsEnabled = false; //billTypeRadGridView.CommitEdit(); //billTypeDomainDataSource.DomainContext.SubmitChanges(OnSubmitCompleted, null); } private void cancelRBTN_Click(object sender, RoutedEventArgs e) { xxTable1DataSource.DomainContext.RejectChanges(); xxTable2DataSource.DomainContext.RejectChanges(); } ////////// Handle Update Concurrency/////////////////// private void OnSubmitCompleted(SubmitOperation so) { //saveRBTN.IsEnabled = true; if (so.HasError) { hasConcurrencyIssue = false; foreach (Entity entity in so.EntitiesInError) { //Process entity conflict concurrency if (entity.EntityConflict != null) { hasConcurrencyIssue = true; RadWindow.Alert("An update concurrency issue occurs.", closed); break; } } so.MarkErrorAsHandled(); if (!hasConcurrencyIssue) { MessageBox.Show("Save failed."); } } else { MessageBox.Show("Save successfully."); } } private void closed(object sender, WindowClosedEventArgs e) { xxTable1DataSource.Clear(); xxTable1DataSource.Load(); xxTable2DataSource.Clear(); xxTable2DataSource.Load(); } #endregion #region Save closing feature private void RadWindow_Closed(object sender, WindowClosedEventArgs e) { } #endregion // OnDragQuery event handler private void OnDragQuery(object sender, DragDropQueryEventArgs e) { RadGridView gridView = sender as RadGridView; if (gridView != null) { e.Options.Payload = gridView.SelectedItem; } e.QueryResult = true; e.Handled = true; } // OnDragInfo event handler private void OnDragInfoxxTable1(object sender, DragDropEventArgs e) { RadGridView gridView = sender as RadGridView; xxTable1 draggedItem = e.Options.Payload as xxTable1; if (e.Options.Status == DragStatus.DragInProgress) { //Setting up a drag cue: ContentControl cue = new ContentControl(); //Choosing a template for the items: //cue.ContentTemplate = this.Resources["ProductTemplate"] as DataTemplate; cue.Content = draggedItem; e.Options.DragCue = cue; } else if (e.Options.Status == DragStatus.DragComplete) { //deleting the dragged item from the RadGridView IList<xxTable1> source = gridView.ItemsSource as IList<xxTable1>; gridView.Items.Remove(draggedItem); // source.Remove(draggedItem); } } private void OnDragInfoxxTable2(object sender, DragDropEventArgs e) { RadGridView gridView = sender as RadGridView; xxTable2 draggedItem = e.Options.Payload as xxTable2; if (e.Options.Status == DragStatus.DragInProgress) { //Setting up a drag cue: ContentControl cue = new ContentControl(); //Choosing a template for the items: //cue.ContentTemplate = this.Resources["ProductTemplate"] as DataTemplate; cue.Content = draggedItem; e.Options.DragCue = cue; } else if (e.Options.Status == DragStatus.DragComplete) { //deleting the dragged item from the RadGridView IList<xxTable2> source = gridView.ItemsSource as IList<xxTable2>; gridView.Items.Remove(draggedItem); // source.Remove(draggedItem); } } // OnDropQuery event handler private void OnDropQuery(object sender, DragDropQueryEventArgs e) { RadGridView destination = sender as RadGridView; if (destination != null) { e.Handled = true; e.QueryResult = true; } } // OnDropInfo event handler private void OnDropInfoxxTable1(object sender, DragDropEventArgs e) { RadGridView destination = sender as RadGridView; xxTable1 draggedItem = e.Options.Payload as xxTable1; if (e.Options.Status == DragStatus.DropComplete) { xxTable2 x = new xxTable2(); x.Description = draggedItem.Description; x.Amount = draggedItem.Amount; (xxTable2DataSource.DomainContext as SilverFinancials.Web.Services.xxTable2).xxTable2s.Add(x); //billTypeRadGridViewDrop.ItemsSource= xxTable2DataSource; xxTable2DataSource.DomainContext.SubmitChanges(); //xxTable2DataSource.Clear(); billTypeRadGridViewDrop.ItemsSource = null; // billTypeRadGridViewDrop.ItemsSource = xxTable2DataSource.DomainContext.Load(SilverFinancials.Web.Services.xxTable2()) ; xxTable2DataSource.Clear(); xxTable2DataSource.Load(); // billTypeRadGridViewDrop.ItemsSource = xxTable2DataSource; // billTypeRadGridViewDrop //// xxTable2DataSource.DataView.Add(draggedItem); //xxTable2DataSource.DomainContext. // destination.Items.Add(x); //(destination.ItemsSource as IList<xxTable2>).Add(e.Options.Payload as xxTable2); } ///xxTable2DataSource.Clear(); //xxTable2DataSource.Load(); } private void OnDropInfoxxTable2(object sender, DragDropEventArgs e) { RadGridView destination = sender as RadGridView; xxTable2 draggedItem = e.Options.Payload as xxTable2; if (e.Options.Status == DragStatus.DropComplete) { xxTable1 x = new xxTable1(); x.Description = draggedItem.Description; x.Amount = draggedItem.Amount; (xxTable1DataSource.DomainContext as SilverFinancials.Web.Services.xxTable1).xxTable1s.Add(x); //billTypeRadGridViewDrop.ItemsSource= xxTable2DataSource; xxTable1DataSource.DomainContext.SubmitChanges(); //xxTable2DataSource.Clear(); billTypeRadGridViewDrop.ItemsSource = null; // billTypeRadGridViewDrop.ItemsSource = xxTable2DataSource.DomainContext.Load(SilverFinancials.Web.Services.xxTable2()) ; xxTable1DataSource.Clear(); xxTable1DataSource.Load(); // billTypeRadGridViewDrop.ItemsSource = xxTable2DataSource; // billTypeRadGridViewDrop //// xxTable2DataSource.DataView.Add(draggedItem); //xxTable2DataSource.DomainContext. // destination.Items.Add(x); //(destination.ItemsSource as IList<xxTable2>).Add(e.Options.Payload as xxTable2); } ///xxTable2DataSource.Clear(); //xxTable2DataSource.Load(); } void TaskDDS_SubmittedChanges(object sender, SubmittedChangesEventArgs e) { //dc.Load(dc.GetReportsQuery()); //// Report is the name of usercotrol //// RepDataGrid is the name of DataGrid control is inside the Report //Report.RepDataGrid.ItemsSource = dc.Reports; } }}