Dear Mr.Tsvyatko,
I am learning to work with Silverlight Business Application which uses Telerik Components.
I am trying to drag a row from RadGridView which inside one RadPane and drop it to another RadGridView.
I have read your thread on "How to drag and drop rows between 2 GridViews" and tried to solve my problem.
It worked but I have to drag these RadPanes from RadDocking and keep folating them. And one more thing instead
of getting position ( var row = e.GetElement<GridViewRow>(e.Options.CurrentDragPoint), I tried to get frameworkelement and checked the name of the GridView as below
else if (e.Options.Status == DragStatus.DropComplete)
{
//get current row on the destination grid
FrameworkElement myelement = e.Options.Destination;
string dgName = myelement.Name;
//var row = e.GetElement<GridViewRow>(e.Options.Destination);
if (myDG.Name == dgName)
{
foreach (var draggedItem in draggedItems.OfType<AssetItem>())
{
// data.RelatedAssets.Add(draggedItem);
draggedincidentAssets.Add(draggedItem);
}
}
incidnetAssetgridview.ItemsSource = draggedincidentAssets;
}
But how can drag row from one RadGridView to another RadGridView which are in two separate RadPanes, and without dragging Radpanes and keep them floating.
I want RadPanes keep docked.
I want to drag the row from assetDG (Whihc is inside Pane 6), when drag complets amd mouse Entered on Pane5, Pane5 should be expanded,
and then once mouse is released on row of the incidentDG, I want the dragged row to be added on incidentAssetDG (which is Row deatils of incidentDG).
I have tried every single way to capture the focus of Pane5 my capturing event...but it didn't work :(
Can you please help me in this case.
Here is my code snippets. Thank you in advance. Waiting for your reply!
Xaml
<telerik:RadDocking x:Name="radDocking1" Grid.Row="1" ElementLoaded="radDocking1_ElementLoaded">
<telerik:RadDocking.DocumentHost>
<telerik:RadSplitContainer telerik:DockingPanel.InitialSize="200,400"
x:Name="BottomContainer" InitialPosition="DockedBottom">
<telerik:RadPaneGroup x:Name="Group3">
<telerik:RadPane x:Name="Pane5" Header="Incidents" MouseEnter="Pane5_MouseEnter">
<telerik:RadDockPanel>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="40" />
<RowDefinition />
</Grid.RowDefinitions>
<telerik:RadToolBar Grid.Row="0">
<TextBlock Text="Search Incidents " />
<TextBox x:Name="textBoxFilterValue" Background="White" TextChanged="FilterValue_TextChanged" Height="20" Width="150" BorderBrush="Black" />
<telerik:RadToolBarSeparator />
<telerik:RadToolBarSeparator />
<TextBlock Text="Threat Levels " />
<ComboBox x:Name="threatLevelsDD" Height="22" Width="150" VerticalAlignment="Center" HorizontalAlignment="Center" BorderBrush="Black" Loaded="CreateThreatLevelsDD_Loaded">
<ComboBox.ItemTemplate>
<DataTemplate>
<CheckBox x:Name="threatLevelsCB" Content="{Binding Path=ThreatLevel}" IsChecked="{Binding Path=IsChecked}" Checked="threatLevelsCB_Checked" Unchecked="threatLevelsCB_Unchecked" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</telerik:RadToolBar>
<telerik:RadBusyIndicator IsBusy="{Binding IsBusy, ElementName=incidentSrc}" Grid.Row="1">
<telerik:RadGridView x:Name="incidentDG"
IsReadOnly="True"
ItemsSource="{Binding Data, ElementName=incidentSrc}"
AutoExpandGroups="True"
Height="Auto"
Margin="0"
CanUserDeleteRows="False"
AutoGenerateColumns="False" dragdrop:RadDragAndDropManager.AllowDrop="True">
<telerik:RadGridView.Columns>
<telerik:GridViewToggleRowDetailsColumn x:Name="colRowToggle"/>
<telerik:GridViewDataColumn x:Name="colName" Header="Name" DataMemberBinding="{Binding Name}"/>
<telerik:GridViewDataColumn x:Name="colType" Header="Type" DataMemberBinding="{Binding Type}"/>
<telerik:GridViewDataColumn x:Name ="colDate" Header="Date Created" DataMemberBinding="{Binding Date}"/>
<telerik:GridViewDataColumn x:Name="colTime" Header="Last Update" DataMemberBinding="{Binding LastTime}"/>
</telerik:RadGridView.Columns>
<telerik:RadGridView.RowDetailsTemplate>
<DataTemplate>
<telerik:RadTabControl BackgroundVisibility="Collapsed" x:Name="RadTabControl1" Margin="8" VerticalAlignment="Center" Background="Transparent" >
<telerik:RadGridView x:Name="incidentAssetDG" AutoExpandGroups="True"
Height="200" Width="Auto" Margin="0,1" CanUserDeleteRows="False" AutoGenerateColumns="False" dragdrop:RadDragAndDropManager.AllowDrop="True" Loaded="incidentAssetDG_Loaded" ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.VerticalScrollBarVisibility="Visible" >
<telerik:RadGridView.RowStyle>
<Style TargetType="gridParts:GridViewRow">
<Setter Property="Background">
<Setter.Value>
<SolidColorBrush Color="#FFB295ED"></SolidColorBrush>
</Setter.Value>
</Setter>
</Style>
</telerik:RadGridView.RowStyle>
<telerik:RadGridView.Columns>
<telerik:GridViewToggleRowDetailsColumn x:Name="colAssetRowToggle"/>
<telerik:GridViewDataColumn x:Name="colAssetName" Header="Name" DataMemberBinding="{Binding Name}"/>
<telerik:GridViewDataColumn x:Name="colAssetType" Header="Type" DataMemberBinding="{Binding Type}"/>
<telerik:GridViewDataColumn x:Name ="colAssetSpeed" Header="Speed" DataMemberBinding="{Binding Speed}"/>
<telerik:GridViewDataColumn x:Name="colAssetLastUpdate" Header="Last Update" DataMemberBinding="{Binding LastTime}"/>
<telerik:GridViewDataColumn x:Name="colAssetStatus" Header="Status" DataMemberBinding="{Binding Status}"/>
<telerik:GridViewCheckBoxColumn x:Name="showOnMap" Header="Visible"/>
</telerik:RadGridView.Columns>
</telerik:RadGridView>
</telerik:RadTabItem>
</telerik:RadTabControl>
</DataTemplate>
</telerik:RadGridView.RowDetailsTemplate>
</telerik:RadGridView>
</telerik:RadBusyIndicator>
</Grid>
</telerik:RadDockPanel>
</telerik:RadPane>
<telerik:RadPane x:Name="Pane6" Header="Assets">
<telerik:RadDockPanel>
<Grid>
<telerik:RadBusyIndicator IsBusy="{Binding IsBusy, ElementName=assetSrc}">
<telerik:RadGridView x:Name="assetDG"
ItemsSource="{Binding Data, ElementName=assetSrc}"
AutoExpandGroups="True"
Height="Auto" Margin="0" CanUserDeleteRows="False" AutoGenerateColumns="False" IsSynchronizedWithCurrentItem="True" dragdrop:RadDragAndDropManager.AllowDrag="True">
<telerik:RadGridView.Columns>
<telerik:GridViewToggleRowDetailsColumn x:Name="colAssetRowToggle"/>
<telerik:GridViewDataColumn x:Name="colAssetName" Header="Name" DataMemberBinding="{Binding Name}"/>
<telerik:GridViewDataColumn x:Name="colAssetType" Header="Type" DataMemberBinding="{Binding Type}"/>
<telerik:GridViewDataColumn x:Name ="colAssetSpeed" Header="Speed" DataMemberBinding="{Binding Speed}"/>
<telerik:GridViewDataColumn x:Name="colAssetLastUpdate" Header="Last Update" DataMemberBinding="{Binding LastTime}"/>
<telerik:GridViewDataColumn x:Name="colAssetStatus" Header="Status" DataMemberBinding="{Binding Status}"/>
<telerik:GridViewCheckBoxColumn x:Name="showOnMap" Header="Visible"/>
</telerik:RadGridView.Columns>
</telerik:RadGridView>
</Grid>
</telerik:RadDockPanel>
</telerik:RadPane">
</telerik:RadPaneGroup>
</telerik:RadSplitContainer>
</telerik:RadDocking>
CS(Code behind)
public partial class Main :Page
{
Global Variables
public CCMain()
{
RadDragAndDropManager.AddDragQueryHandler(assetDG, OnassetDGDragQuery);
RadDragAndDropManager.AddDragInfoHandler(assetDG, OnassetDGDragInfo);
RadDragAndDropManager.AddDropQueryHandler(newincidentAssetDG, OnnewincidentAssetDGDropQuery);
RadDragAndDropManager.AddDropInfoHandler(newincidentAssetDG, OnnewincidentAssetDGDropInfo);
}
private void OnassetDGDragQuery(object sender, DragDropQueryEventArgs e)
{
//if (e.Options.Source is GridViewHeaderCell || e.Options.Source is GridViewGroupPanelCell)
// return;
RadGridView assetgridView = sender as RadGridView;
if (assetgridView != null)
{
IList selectedItems = assetgridView.SelectedItems.ToList();
if (selectedItems.Count > 1)
{
MessageBox.Show("Please select the single item");
}
if (selectedItems.Count == 1)
{
e.QueryResult = selectedItems.Count > 0;
e.Options.Payload = selectedItems;
}
}
var cue = new TreeViewDragCue();
//cue.DragActionContent = "I AM BEING DRAGGING...";
e.Options.DragCue = cue;
e.QueryResult = true;
e.Handled = true;
// Debug.WriteLine("I am in OnassetDGDragQuery....Drsgging");
}
private void OnassetDGDragInfo(object sender, DragDropEventArgs e)
{
//if (e.Options.Source is GridViewHeaderCell || e.Options.Source is GridViewGroupPanelCell)
// return;
RadGridView assetgridView = sender as RadGridView;
IEnumerable draggedItems = e.Options.Payload as IEnumerable;
if (e.Options.Status == DragStatus.DragInProgress)
{
//Set up a drag cue:
TreeViewDragCue cue = new TreeViewDragCue();
//Here we need to choose a template for the items:
cue.ItemTemplate = this.Resources["AssetTemplate"] as DataTemplate;
cue.ItemsSource = draggedItems;
e.Options.DragCue = cue;
//Debug.WriteLine("Dragging!!!");
}
else if (e.Options.Status == DragStatus.DragComplete)
{
//IList source = gridView.ItemsSource as IList;
//foreach (object draggedItem in draggedItems)
//{
// source.Remove(draggedItem);
//}
//Debug.WriteLine("Drag Completed....");
//e.Options.
}
// Point mypoint = e.Options.MouseClickPoint;
//Debug.WriteLine("point"+mypoint);
}
private void OnnewincidentAssetDGDropQuery(object sender, DragDropQueryEventArgs e)
{
//if (e.Options.Source is GridViewHeaderCell || e.Options.Source is GridViewGroupPanelCell)
// return;
// We allow drop only if the dragged items are Assets and the destination grid is the top most one:
ICollection draggedItems = e.Options.Payload as ICollection;
var destinationRow = e.GetElement<GridViewRow>(e.Options.CurrentDragPoint);
//bool result = draggedItems.Cast<object>().All((object item) => item is AssetItem) &&
// destinationRow != null && destinationRow.GridViewDataControl.ChildTableDefinitions.Count > 0 || destinationRow == null;
bool result = draggedItems.Cast<object>().All((object item) => item is AssetItem) &&
(destinationRow != null ) || destinationRow == null;
// bool result = draggedItems.Cast<object>().All((object item) => item is AssetItem) && destinationRow != null || destinationRow == null;
e.QueryResult = result;
e.Handled = true;
if (result)
{
TreeViewDragCue cue = e.Options.DragCue as TreeViewDragCue;
cue.IsDropPossible = true;
}
// Note that here we agree to accept a drop. We will be notified
// in the DropInfo event whether a drop is actually possible.
// Debug.WriteLine("I am in OnnewIncidentAssetDGDropQuery....");
}
ObservableCollection<AssetItem> draggedAssets = new ObservableCollection<AssetItem>();
private void OnnewincidentAssetDGDropInfo(object sender, DragDropEventArgs e)
{
RadGridView myDG = sender as RadGridView;
//if (e.Options.Source is GridViewHeaderCell || e.Options.Source is GridViewGroupPanelCell)
// return;
RadGridView incidnetAssetgridview = e.Options.Destination as RadGridView;
ICollection draggedItems = e.Options.Payload as ICollection;
// Get the drag cu that the TreeView or we have created
TreeViewDragCue cue = e.Options.DragCue as TreeViewDragCue;
if (e.Options.Status == DragStatus.DropPossible && incidnetAssetgridview != null)
{
// Set a suitable text:
string newString;
newString = String.Format("Add {0}", draggedItems.Count);
cue.DragActionContent = newString;
cue.IsDropPossible = true;
incidnetAssetgridview.Background = this.Resources["DropPossibleBackground"] as Brush;
}
else if (e.Options.Status == DragStatus.DropImpossible)
{
cue.DragActionContent = null;
cue.IsDropPossible = false;
}
else if (e.Options.Status == DragStatus.DropComplete)
{
//get current row on the destination grid
FrameworkElement myelement = e.Options.Destination;
string dgName = myelement.Name;
//var row = e.GetElement<GridViewRow>(e.Options.Destination);
if (myDG.Name == dgName)
{
foreach (var draggedItem in draggedItems.OfType<AssetItem>())
{
// data.RelatedAssets.Add(draggedItem);
draggedAssets.Add(draggedItem);
}
}
//var row = (GridViewRow)myDG.ChildrenOfType<GridViewRow>();
//var row = e.GetElement<GridViewRow>(e.Options.DestinationCue);
//if (row != null)
//{
//myDG.DataContext as
//// var data = row.DataContext as AssetItem;
// var data= myDG.DataContext as AssetItem;
// if (data != null)
// {
// foreach (var draggedItem in draggedItems.OfType<AssetItem>())
// {
// // data.RelatedAssets.Add(draggedItem);
// draggedAssets.Add(draggedItem);
// }
// }
incidnetAssetgridview.ItemsSource = draggedAssets;
}
if (e.Options.Status != DragStatus.DropPossible && incidnetAssetgridview != null)
{
incidnetAssetgridview.Background = new SolidColorBrush(Colors.White);
}
// Debug.WriteLine("I am in OnnewIncidentAssetDGDropInfo....");
}
Sincerely,
Vishakha