This is a migrated thread and some comments may be shown as answers.

TreeListView question

9 Answers 164 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
Fabiana
Top achievements
Rank 1
Fabiana asked on 05 May 2010, 12:46 PM
Hello! I would like to know how to remove a second line in RadTreeLIstView, with the text "PersonName". I would like to appear just First and Last Name when click in RadTreeLIstView. I created a RadTreeListView with 2 columns and a NamedLIst() class.

Another question is: I inserted IsEditable="True", but I canĀ“t edit, why ?



See my example and attached image:

-----------------------------------------MainPage.xaml ----------------------------
<UserControl x:Class="SilverlightApplication1.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:SilverlightApplication1"
        xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"
        xmlns:nav="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation"
             mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             Height="213" Width="469" xmlns:my="clr-namespace:Telerik.Windows.Controls.TreeView;assembly=Telerik.Windows.Controls.Navigation">


    <nav:RadTreeListView Background="White" x:Name="RadTreeListViewTest" BorderBrush="#a9a9a9" BorderThickness="1" HorizontalContentAlignment="Center" Width="415" Height="170"
                         IsDragDropEnabled="False" IsDragPreviewEnabled="False" IsDragTooltipEnabled="False"
                                                    SelectionMode="Single"
                                                    IsSingleExpandPath="False"
                                                    IsExpandOnSingleClickEnabled="True"
                                                    IsLineEnabled="True" IsEditable="True">

        <nav:RadTreeListView.Columns>

            <nav:RadColumn Header="First Name" PropertyName="FirstName" Width="150" IsEditable="True" >
                <nav:RadColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock Foreground="#284869" Text="{Binding FirstName}" VerticalAlignment="Center" />
                    </DataTemplate>
                </nav:RadColumn.CellTemplate>
            </nav:RadColumn>

            <nav:RadColumn Header="Last Name" PropertyName="LastName" Width="150" IsEditable="True">
                <nav:RadColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock Foreground="#284869" Text="{Binding LastName}" VerticalAlignment="Center" />
                    </DataTemplate>
                </nav:RadColumn.CellTemplate>
            </nav:RadColumn>



        </nav:RadTreeListView.Columns>


    </nav:RadTreeListView>

</UserControl>

----------------------------------MainPage.xaml.cs-------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections;
using System.Collections.ObjectModel;


namespace SilverlightApplication1
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();

             //Add only Folders, after click add parents...
            IList itemsSource = new ObservableCollection<object>();
            itemsSource = new NameList();

            this.RadTreeListViewTest.ItemsSource = itemsSource;

        
        }
    }
}



------------------------------NamedList() class--------------------------



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;


    public class NameList : ObservableCollection<PersonName>
    {
        public NameList(): base()
        {
            Add(new PersonName("XX", "11"));
            Add(new PersonName("WW", "22"));
            Add(new PersonName("AA", "33"));
            Add(new PersonName("QQ", "44"));
            Add(new PersonName("RR", "55"));
        }
    }

    public class PersonName
    {
        private string firstName;
        private string lastName;

        public PersonName(string first, string last)
        {
            this.firstName = first;
            this.lastName = last;
        }

        public string FirstName
        {
            get { return firstName; }
            set { firstName = value; }
        }

        public string LastName
        {
            get { return lastName; }
            set { lastName = value; }
        }
    }



9 Answers, 1 is accepted

Sort by
0
Miroslav
Telerik team
answered on 05 May 2010, 03:13 PM
Hello Fabiana,

This PersonName string comes from the default ItemTemplate of the TreeListVIew. The ItemTemplate is used as a details view in this case.

Assigning an empty data template (containing just a Grid for example) should hide this.

Please note that using inline templates in SL4 may lead to bad memory leaks, more info here (this is due to a bug):

http://forums.silverlight.net/forums/t/171739.aspx

All the best,
Miroslav
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Fabiana
Top achievements
Rank 1
answered on 05 May 2010, 05:04 PM
Hello Miroslav.

Thank you for information, but I am having some questions using RadTreeListView in all my test application before buy Telerik Controls for silverlight. I know that is not a final version, but if possible, can you change my RadTreeListView, to exclude details line in each node, and resolve memory leak? Can you send for me a good way to do it? Because I will use this similar code in an application to show for people, and they will decide if we will buy telerik, based on performance, etc... etc...So itĀ“s very importante for us before decide something. Thank you very much!!



 <nav:RadTreeListView Background="White" x:Name="RadTreeListViewTest" BorderBrush="#a9a9a9" BorderThickness="1" HorizontalContentAlignment="Center" Width="415" Height="170"
                         IsDragDropEnabled="False" IsDragPreviewEnabled="False" IsDragTooltipEnabled="False"
                                                    SelectionMode="Single"
                                                    IsSingleExpandPath="True"
                                                    IsExpandOnSingleClickEnabled="True"
                                                    IsLineEnabled="True" IsEditable="True">
        
  
            <nav:RadTreeListView.Columns>

            <nav:RadColumn Header="First Name" PropertyName="FirstName" Width="150" IsEditable="True">
                
                <nav:RadColumn.CellTemplate>
                    <DataTemplate >
                       <TextBlock Foreground="#284869" Text="{Binding FirstName}" VerticalAlignment="Center" />  
                    </DataTemplate>
                </nav:RadColumn.CellTemplate>
            </nav:RadColumn>

            <nav:RadColumn Header="Last Name" PropertyName="LastName" Width="150" IsEditable="True">
                <nav:RadColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock Foreground="#284869" Text="{Binding LastName}" VerticalAlignment="Center" />
                    </DataTemplate>
                </nav:RadColumn.CellTemplate>
            </nav:RadColumn>



        </nav:RadTreeListView.Columns>


    </nav:RadTreeListView>
0
Miroslav
Telerik team
answered on 06 May 2010, 02:21 PM
Hi Fabiana,

Of course, I can do this for you.

The attached project is based on the code you pasted and has the changes I mentioned. It is a Silverlight 4 project, VS 2010.

Do get back to us if you have questions or need more help.

All the best,
Miroslav
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Fabiana
Top achievements
Rank 1
answered on 06 May 2010, 03:06 PM
Hello Miroslav!!

Thank you very much for project. Now, I am stating understand this control. Before you sent this example for me, I created a ticket, ... so ignore my ticket, I will close it now!

I have just 2 questions based in this modified example:

1) "LastName" column  data into a combobox control. How to do it ?
2) User will edit just "FirstName" column data. How to do it ?

Can you modify your example ? After this, I can continuous with my application tester...
Thank you very much!
0
Miroslav
Telerik team
answered on 06 May 2010, 03:27 PM
Hi Fabiana,

You can put a ComboBox as the cell's content. The ItemsSource of the ComboBox may come from different sources. I have shown just one way to bind it but this may not always be a good approach.

The first column can be edited by setting its CellEditTemplate.

The modified project is attached.

Hopefully this will help you,

All the best,
Miroslav
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Fabiana
Top achievements
Rank 1
answered on 06 May 2010, 04:41 PM
Hi Miroslav!
Thank you very much for your example. Now I can continuous with my tests with RadTreeListView!

0
Fabiana
Top achievements
Rank 1
answered on 10 May 2010, 06:14 PM
Hi Miroslav.

Based in your good example, I have one more question: I want to insert a column that show status ( "read" for value 1 and "unread" for value 2). How to do it?
I created a Status column, with Combobox... I changed Class... but how to insert JUST  "read" and "unread" options in this combo status, and select correct status based on binding class ( 1 or 2 ) ?
Thanks!!!




<UserControl x:Class="SilverlightApplication1.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:SilverlightApplication1"
        xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
        xmlns:nav="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation"
             mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             Height="213" Width="660"
             xmlns:my="clr-namespace:SilverlightApplication1"
             
             >

    <UserControl.Resources>
        
        <my:NameList x:Key="comboStatusSource"/>
        
        <telerik:CellTemplate x:Key="firstNameTemplate" >
            <TextBlock Foreground="#284869" Text="{Binding FirstName}" VerticalAlignment="Center"  Margin="2"/>
        </telerik:CellTemplate>

        <telerik:CellTemplate x:Key="firstNameEditTemplate" >
            <TextBox Foreground="#284869" Text="{Binding FirstName, Mode=TwoWay}" VerticalAlignment="Center" />
        </telerik:CellTemplate>

        <telerik:CellTemplate x:Key="lastNameTemplate" >
            <TextBlock Foreground="#284869" Text="{Binding LastName}" VerticalAlignment="Center"  Margin="2"/>
        </telerik:CellTemplate>
        
        <telerik:CellTemplate x:Key="statusNameTemplate">
            <telerik:RadComboBox Text="{Binding Status, Mode=TwoWay}" DisplayMemberPath="Status"  ItemsSource="{Binding Source={StaticResource comboStatusSource}}" IsEditable="True" IsFilteringEnabled="True" IsReadOnly="False" Foreground="#284869" Margin="2"/>
        </telerik:CellTemplate>
        
        <DataTemplate x:Key="itemTemplate">
            <Grid />
        </DataTemplate>

    </UserControl.Resources>
    
    

    <nav:RadTreeListView Background="White" x:Name="RadTreeListViewTest" BorderBrush="#a9a9a9" BorderThickness="1" HorizontalContentAlignment="Center" Width="574" Height="170"
                         IsDragDropEnabled="False" IsDragPreviewEnabled="False" IsDragTooltipEnabled="False"
                         IsEditable="True"
                                                    SelectionMode="Single"
                         ItemTemplate="{StaticResource itemTemplate}"
                                                    IsSingleExpandPath="False"
                                                    IsExpandOnSingleClickEnabled="True"
                                                    IsLineEnabled="True" >

        <nav:RadTreeListView.Columns>

            <nav:RadColumn Header="First Name" PropertyName="FirstName" Width="150" IsEditable="True" CellTemplate="{StaticResource firstNameTemplate}"
                           CellEditTemplate="{StaticResource firstNameEditTemplate}" />

            <nav:RadColumn Header="Last Name" PropertyName="LastName" Width="150" IsEditable="False" CellTemplate="{StaticResource lastNameTemplate}" />

            <nav:RadColumn Header="Status" PropertyName="Status" Width="150" IsEditable="False" CellTemplate="{StaticResource statusNameTemplate}" />

        </nav:RadTreeListView.Columns>


    </nav:RadTreeListView>

</UserControl>



----CLASS--------------

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 System.ComponentModel;

namespace SilverlightApplication1
{
    public class NameList : ObservableCollection<PersonName>
    {
        public NameList()
            : base()
        {
            Add(new PersonName("XX", "1DD",1)); // 1=unread
            Add(new PersonName("WW", "TDD2",2)); // 2=read
            Add(new PersonName("AA", "ED188",1)); // 1=unread
            Add(new PersonName("QQ", "RR1",1)); // 1=unread
            Add(new PersonName("RR", "KJ2",2)); // 2=read
        }
    }

    public class PersonName : INotifyPropertyChanged
    {
        public PersonName(string first, string last, int status)
        {
            this.firstName = first;
            this.lastName = last;
            this.status = status;
        }


        private String firstName;
        /// <summary>
        ///     Gets or sets the first name.
        /// </summary>
        public String FirstName
        {
            get
            {
                return this.firstName;
            }
            set
            {
                if (this.firstName != value)
                {
                    this.firstName = value;
                    OnPropertyChanged("FirstName");
                }
            }
        }



        private String lastName;
        /// <summary>
        ///     Gets or sets the last name.
        /// </summary>
        public String LastName
        {
            get
            {
                return this.lastName;
            }
            set
            {
                if (this.lastName != value)
                {
                    this.lastName = value;
                    OnPropertyChanged("LastName");
                }
            }
        }


        private int status;
        /// <summary>
        ///     Gets or sets the last name.
        /// </summary>
        public int Status
        {
            get
            {
                return this.status;
            }
            set
            {
                if (this.status != value)
                {
                    this.status = value;
                    OnPropertyChanged("Status");
                }
            }
        }


        /// <summary>
        ///     Event for INotifyPropertyChanged.
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        ///     Raises the INotifyPropertyChanged event.
        /// </summary>
        /// <param name="propertyName">The property to be included in the INotifyPropertyChanged EventArgs.</param>
        protected virtual void OnPropertyChanged(String propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

    }

}
0
Accepted
Miroslav
Telerik team
answered on 13 May 2010, 03:48 PM
Hi Fabiana,

This can be done with a value converter in the ItemTemplate of the ComboBox.

I have done this in the attached project.

Hopefully this will help you.

Sincerely yours,
Miroslav
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Fabiana
Top achievements
Rank 1
answered on 18 May 2010, 08:30 PM
Thank you very much Miroslav!!!
Tags
TreeListView
Asked by
Fabiana
Top achievements
Rank 1
Answers by
Miroslav
Telerik team
Fabiana
Top achievements
Rank 1
Share this question
or