I have a telerik RadTreeListView which is populated by a C# DataTable class. All i want is to refresh the RadTreeListView UI when items are removed or added to the DataTable (i dont care about when item properties change for now).
I have looked into and tried using the ObservableCollection class, when i remove or add items to the dataTable, i can see from the debugger that the dt object has changed but the the problem is that the RadTreeListView does not update. It still shows the same old data even when i call its Rebind method.
RadTreeViewList XAML
<telerik:RadTreeListView x:Name="radTreeListView" ItemsSource="{Binding Items}"
SelectionMode="Multiple" AutoGenerateColumns="False" FontSize="11" SelectionChanged="radTreeListView_SelectionChanged">
<telerik:RadTreeListView.ChildTableDefinitions>
<telerik:TreeListViewTableDefinition ItemsSource="{Binding Items}" />
</telerik:RadTreeListView.ChildTableDefinitions>
<telerik:RadTreeListView.Columns >
<telerik:GridViewSelectColumn />
<telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" Header="Name" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding StartDate}" Header="Start Date" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding EndDate}" Header="End Date" />
</telerik:RadTreeListView.Columns>
</telerik:RadTreeListView>
C# Class
namespace ProjectServerDashboard
{
public class Test : ObservableCollection<Test>
{
private Test(string strName, string strID, string StartDate, string EndDate, string strParentId,Test Cat_parent)
{
ParentId = strParentId;
Name = strName;
ID = strID;
this.StartDate = StartDate;
this.EndDate = EndDate;
Parent = Cat_parent;
Items = new ObservableCollection<Test>();
}
public string ID { get; set; }
public string Name { get; set; }
public string StartDate { get; set; }
public string EndDate { get; set; }
public string ParentId { get; set; }
Test Parent { get; set; }
public new ObservableCollection<Test> Items { get; set; }
public static ObservableCollection<Test> GetWarehouseData(DataTable dt)
{
var clubs = new ObservableCollection<Test>();
Test parent = null;
Test firstChild = null;
Test secondChild = null;
for (int i = 0; i < dt.Rows.Count; i++)
{
string strTaskParentUID = Convert.ToString(dt.Rows[i]["TID"]).Trim();
string strTaskID = Convert.ToString(dt.Rows[i]["TID"]).Trim();
string strTaskName = Convert.ToString(dt.Rows[i]["TName"]);
string strTaskStartDate = Convert.ToString(dt.Rows[i]["TDate"]);
string strTaskEndDate = Convert.ToString(dt.Rows[i]["TEndDate"]);
int TaskOutlineLevel = Convert.ToInt32(dt.Rows[i]["TLevel"]);
if (i == 0 && TaskOutlineLevel == 1)
{
parent = new Test(strTaskName, strTaskID, strTaskStartDate, strTaskEndDate,strTaskParentUID, null);
}
else
{
switch (TaskOutlineLevel)
{
case 2:
firstChild = new Test(strTaskName, strTaskID, strTaskStartDate, strTaskEndDate,
strTaskParentUID, parent);
if (parent.ID == strTaskParentUID)
{
parent.Items.Add(firstChild);
}
break;
case 3:
secondChild = new Test(strTaskName, strTaskID, strTaskStartDate, strTaskEndDate,
strTaskParentUID, firstChild);
if (firstChild.ID == secondChild.ParentId)
{
firstChild.Items.Add(secondChild);
}
break;
}
}
}
clubs.Add(parent);
SessionApp.SessionManager.Session["myDataTable"] = clubs
return clubs;
}
}
}
The RadTreeView's UI is supposed to update after i call the code below from my MainPage.xaml.cs
NestedTreeView objNestedTreeView = new NestedTreeView();
objNestedTreeView.radTreeListView.ItemsSource = Test.GetWarehouseData((DataTable)SessionApp.SessionManager.Session["myDataTable"]);