Hi,
I have a treeview hooked up to an oberserverble collection and a hieracical template.
I am working on drag and drop in the treeview. How ever when dragging node test 011 .... up under test 001... (see treeview1) , and toggle the node expanders I get (treeview2a) , where it correctly has been removed from it source node, but only a white space has come on its destination node. clicking the whitespace make a dotted line around the root level node. I have checked in the code behind and verified that the parent node(test00test....) has the correct child nodes in its children property.
Also when dragging a treenode inside another treenode there is a problem. Going from treeview3 to treeview4 you see that it looks like the dragged node gets put under the existing ones.Also here I have to toggle the expand nodes.
my relevent code is,
hope anyone can help!!
I have a treeview hooked up to an oberserverble collection and a hieracical template.
I am working on drag and drop in the treeview. How ever when dragging node test 011 .... up under test 001... (see treeview1) , and toggle the node expanders I get (treeview2a) , where it correctly has been removed from it source node, but only a white space has come on its destination node. clicking the whitespace make a dotted line around the root level node. I have checked in the code behind and verified that the parent node(test00test....) has the correct child nodes in its children property.
Also when dragging a treenode inside another treenode there is a problem. Going from treeview3 to treeview4 you see that it looks like the dragged node gets put under the existing ones.Also here I have to toggle the expand nodes.
my relevent code is,
<
Grid.Resources
>
<!--<local:PriceAreaListProvider x:Key="priceAreaListProvider" />-->
<
telerik:HierarchicalDataTemplate
x:Key
=
"NodeTemplate"
ItemsSource
=
"{Binding Children}"
>
<
StackPanel
Orientation
=
"Horizontal"
>
<
TextBlock
Text
=
"{Binding Heiti}"
TextWrapping
=
"Wrap"
MouseLeftButtonDown
=
"TextBox_MouseLeftButtonDown"
/>
<
TextBlock
Text
=
"{Binding Heiti_e}"
TextWrapping
=
"Wrap"
/>
</
StackPanel
>
</
telerik:HierarchicalDataTemplate
>
</
Grid.Resources
>
<
telerik:RadTreeView
Width
=
"220"
Grid.Row
=
"2"
HorizontalAlignment
=
"Left"
HorizontalContentAlignment
=
"Left"
x:Name
=
"TreeView1"
VerticalAlignment
=
"Top"
ItemTemplate
=
"{StaticResource NodeTemplate}"
ScrollViewer.HorizontalScrollBarVisibility
=
"Auto"
ScrollViewer.VerticalScrollBarVisibility
=
"Auto"
MaxHeight
=
"570"
IsExpandOnSingleClickEnabled
=
"True"
SelectedValuePath
=
"Heiti"
IsEditable
=
"True"
Edited
=
"TreeView1_Edited"
IsDragDropEnabled
=
"True"
DragEnded
=
"TreeView1_DragEnded"
>
<
telerik:RadTreeView.ItemEditTemplate
>
<
DataTemplate
>
<
StackPanel
Orientation
=
"Horizontal"
>
<
TextBox
Text
=
"{Binding Heiti, Mode=TwoWay}"
/>
<
TextBox
Text
=
"{Binding Heiti_e, Mode=TwoWay}"
/>
</
StackPanel
>
</
DataTemplate
>
</
telerik:RadTreeView.ItemEditTemplate
>
</
telerik:RadTreeView
>
private void CostPlanInfoGridView_SelectionChanged(object sender, SelectionChangeEventArgs e)
{
if (CostPlanInfoGridView.SelectedItem!=null)
{
basicContext.tbl_KostKaflars.Clear();
TreeView1.ItemsSource = new HierarchicalDataSourceCustomsChapters(basicContext, ((tbl_KostAaetlun)CostPlanInfoGridView.SelectedItem).ID);
}
}
private
void
TreeView1_DragEnded(
object
sender, RadTreeViewDragEndedEventArgs e)
{
System.Collections.ObjectModel.Collection<
object
> col = e.DraggedItems;
tbl_KostKaflar target = (tbl_KostKaflar) e.TargetDropItem.Item;
tbl_KostKaflar droppedItem = (tbl_KostKaflar)col.First();
//adjust rod in sieblings in the chapter it was dragged from.
List<tbl_KostKaflar> rodadjustListPrev = basicContext.tbl_KostKaflars.Where(t => t.parentID == droppedItem.parentID && t.Rod > droppedItem.Rod).ToList();
foreach
(tbl_KostKaflar item
in
rodadjustListPrev)
{
item.Rod--;
//
}
tbl_KostKaflar PreviousParentKaflar = basicContext.tbl_KostKaflars.Where(t => t.ID == droppedItem.parentID).First();
//PreviousParentKaflar.Children.Remove(droppedItem);
PreviousParentKaflar.Children.Sort(
delegate
(tbl_KostKaflar t1, tbl_KostKaflar t2) {
return
t1.Rod.CompareTo(t2.Rod); });
if
(PreviousParentKaflar.Children.Count==0)
{
PreviousParentKaflar.HasChild =
false
;
}
tbl_KostKaflar parentKaflar;
if
(e.DropPosition==DropPosition.Before)
{
List<tbl_KostKaflar> rodadjustList = basicContext.tbl_KostKaflars.Where(t => t.parentID == target.parentID && t.Rod > target.Rod).ToList();
foreach
(tbl_KostKaflar item
in
rodadjustList)
{
item.Rod++;
//
}
droppedItem.parentID = target.parentID;
droppedItem.Rod = target.Rod;
target.Rod++;
parentKaflar = basicContext.tbl_KostKaflars.Where(t => t.ID == target.parentID).First();
}
else
if
(e.DropPosition==DropPosition.After)
{
droppedItem.Rod = target.Rod + 1;
droppedItem.parentID = target.parentID;
parentKaflar = basicContext.tbl_KostKaflars.Where(t => t.ID == target.parentID).First();
}
else
{
droppedItem.parentID = target.ID;
droppedItem.Rod = target.Children.Count();
parentKaflar = target;
}
//parentKaflar.Children.Add(droppedItem);
parentKaflar.Children.Sort(
delegate
(tbl_KostKaflar t1, tbl_KostKaflar t2) {
return
t1.Rod.CompareTo(t2.Rod); });
parentKaflar.HasChild =
true
;
basicContext.SubmitChanges();
}
using
System;
using
System.Net;
using
System.Windows;
using
System.Windows.Controls;
using
System.Windows.Documents;
using
System.Windows.Ink;
using
System.Windows.Input;
using
System.Windows.Media;
using
System.Windows.Media.Animation;
using
System.Windows.Shapes;
using
System.Collections.ObjectModel;
//using PriceBank.TreeViewService;
using
System.Collections.Generic;
using
System.Linq;
using
PriceBank.Web.Services;
using
System.ServiceModel.DomainServices.Client;
//using PriceBank.Web.DataModels;
namespace
PriceBank
{
public
class
HierarchicalDataSourceCustomsChapters : ObservableCollection<tbl_KostKaflar>
{
private
List<tbl_KostKaflar> unsortedList =
new
List<tbl_KostKaflar>();
private
BuildingCostDomainContext buildContextGlb;
public
HierarchicalDataSourceCustomsChapters(BuildingCostDomainContext buildContext,
int
costplanID)
{
buildContextGlb = buildContext;
buildContext.Load(buildContext.GetTbl_KostKaflarByCostPlanIdQuery(costplanID), priceContextLoaded,
null
);
}
private
void
priceContextLoaded(LoadOperation<tbl_KostKaflar> efni)
{
// transfer all the items from the result to the unsorted list
foreach
(tbl_KostKaflar item
in
efni.AllEntities)
{
//TableItem genericItem = new TableItem(item.Name,item.NodeId,item.ParentID,item.Path,item.WBSID,item.ChapterRanking,item.HasChild, buildContextGlb);
this
.unsortedList.Add(item);
}
// Get all the first level nodes. In our case it is only one - House M.D.
var rootNodes =
this
.unsortedList.Where(x => x.parentID == 0);
// Foreach root node, get all its children and add the node to the HierarchicalDataSource.
// see bellow how the FindChildren method works
foreach
(tbl_KostKaflar node
in
rootNodes)
{
node.nodeLevel = 0;
this
.FindChildren(node);
this
.Add(node);
}
}
private
void
FindChildren(tbl_KostKaflar item)
{
if
(item.nodeLevel<2)
{
// find all the children of the item
var children = unsortedList.Where(x => x.parentID == item.ID && x.ID != item.ID);
if
(item.Children ==
null
)
{
item.Children =
new
List<tbl_KostKaflar>();
}
// add the child to the item's children collection and call the FindChildren recursively, in case the child has children
foreach
(tbl_KostKaflar child
in
children)
{
child.nodeLevel = item.nodeLevel + 1;
item.Children.Add(child);
FindChildren(child);
}
}
}
}
}
hope anyone can help!!