Hello!
I am trying to add information into Telerik TreeListView control.
I did a simple example with 3 columns, but I donĀ“t know how to load information into TreeListView.
See my example. I would like to load data using my Class LoadData(). How to set PARENT NODE into TreeListView ? Is there another way to do it?
Thanks!!
public class DataSource : List<Organization>
{
public DataSource()
{
Organization org = new Organization("OrganizationXYZ", false, true);
Department Sales = new Department("Sales", false, true);
Department Marketing = new Department("Marketing", false, false);
org.Departments.Add(Sales);
org.Departments.Add(Marketing);
Sales.Employees.Add(new Person("Person1", true));
Sales.Employees.Add(new Person("Person2", false));
Sales.Employees.Add(new Person("Person3", false));
Marketing.Employees.Add(new Person("Person4", false));
Marketing.Employees.Add(new Person("Person5", false));
this.Add(org);
}
}
______
public class Organization : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private string name;
private bool selected = false;
private bool expanded = false;
public Organization(string name)
{
this.name = name;
Departments = new List<Department>();
}
public Organization(string name, bool selected, bool expanded)
{
this.name = name;
this.selected = selected;
this.expanded = expanded;
Departments = new List<Department>();
}
public string Name
{
get
{
return this.name;
}
set
{
if (value != this.name)
{
this.name = value;
NotifyPropertyChanged("Name");
}
}
}
public bool Selected
{
get
{
return this.selected;
}
set
{
if (value != this.selected)
{
this.selected = value;
NotifyPropertyChanged("Selected");
}
}
}
public bool Expanded
{
get
{
return this.expanded;
}
set
{
if (value != this.expanded)
{
this.expanded = value;
NotifyPropertyChanged("Expanded");
}
}
}
public List<Department> Departments
{
get;
set;
}
private void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
______
public class Department : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private string name;
private bool selected = false;
private bool expanded = false;
public Department(string name)
{
this.name = name;
Employees = new List<Person>();
}
public Department(string name, bool selected, bool expanded)
{
this.name = name;
this.selected = selected;
this.expanded = expanded;
Employees = new List<Person>();
}
public string Name
{
get
{
return this.name;
}
set
{
if (value != this.name)
{
this.name = value;
NotifyPropertyChanged("Name");
}
}
}
public bool Selected
{
get
{
return this.selected;
}
set
{
if (value != this.selected)
{
this.selected = value;
NotifyPropertyChanged("Selected");
}
}
}
public bool Expanded
{
get
{
return this.expanded;
}
set
{
if (value != this.expanded)
{
this.expanded = value;
NotifyPropertyChanged("Expanded");
}
}
}
public List<Person> Employees
{
get;
set;
}
private void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
______
public class Person : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private string name;
private bool selected = false;
public Person(string name)
{
this.name = name;
}
public Person(string name, bool selected)
{
this.name = name;
this.selected = selected;
}
public string Name
{
get
{
return this.name;
}
set
{
if (value != this.name)
{
this.name = value;
this.NotifyPropertyChanged("Name");
}
}
}
public bool Selected
{
get
{
return this.selected;
}
set
{
if (value != this.selected)
{
this.selected = value;
NotifyPropertyChanged("Selected");
}
}
}
private void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
______
<telerikNavigation:RadTreeListView IsLineEnabled="True" IsEditable="True"
x:Name="RadTreeListView1" Background="White" Margin="10,94,10,309"
BorderBrush="#a9a9a9" BorderThickness="1" SelectionMode="Multiple">
<telerikNavigation:RadTreeListView.Columns>
<telerikNavigation:RadColumn x:Name="RadColumnName" PropertyName="Name" Header="Name">
<telerikNavigation:RadColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="" VerticalAlignment="Center"/>
</DataTemplate>
</telerikNavigation:RadColumn.CellTemplate>
</telerikNavigation:RadColumn>
<telerikNavigation:RadColumn x:Name="RadColumnSelected" PropertyName="Selected" Header="Selected">
<telerikNavigation:RadColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="" VerticalAlignment="Center"/>
</DataTemplate>
</telerikNavigation:RadColumn.CellTemplate>
</telerikNavigation:RadColumn>
<telerikNavigation:RadColumn x:Name="RadColumnExpanded" PropertyName="Expanded" Header="Expanded">
<telerikNavigation:RadColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="" VerticalAlignment="Center" />
</DataTemplate>
</telerikNavigation:RadColumn.CellTemplate>
</telerikNavigation:RadColumn>
</telerikNavigation:RadTreeListView.Columns>
</telerikNavigation:RadTreeListView>
_______
private void LoadData()
{
DataSource dt = new DataSource();
if (dt != null)
{
//Add Organization Name
this.RadTreeListView1.Items.Add(dt[0].Name);
for (int i = 0; i < dt[0].Departments.Count; i++)
{
//Add Departments Name into Organization ?????????????????? ADD IT INTO A PARENT NODE !!!
this.RadTreeListView1.Items.Add(dt[0].Departments[i].Name);
for (int j = 0; j < dt[0].Departments[i].Employees.Count; j++)
{
//Add Employees Name into Departments ?????????????????????? ADD IT INTO A PARENT NODE !!!
this.RadTreeListView1.Items.Add(dt[0].Departments[i].Employees[j].Name);
}
}
}
}