Edit this page

Bind to object data

RadPanelBar can be bound to a collection of objects and dynamically create its collection of items. The collection that is provided as items source can contain either RadPanelBarItems or any other type of objects. If the items source collection contains RadPanelBarItems, they are directly made children of the RadPanelBar control. Otherwise, the objects in the items source collection are wrapped in RadPanelBarItem objects and then are pushed into the Items collection of the RadPanelBar control.

Naturally, if the collection you are binding to implements the INotifyCollectionChanged interface, whenever your source collection is changed, the change would be immediately reflected in the Items collection of the RadPanelBar.

Here is an example of binding a RadPanelBar control to a collection of strings:

C#

List<string> myListDataSource = new List<string>();
myListDataSource.Add("Item 1");
myListDataSource.Add("Item 2");
myListDataSource.Add("Item 3");
RadPanelBar myPanel = new RadPanelBar();
myPanel.ItemsSource = myListDataSource;

VB.NET

Dim myListDataSource As New List(Of String)()
myListDataSource.Add("Item 1")
myListDataSource.Add("Item 2")
myListDataSource.Add("Item 3")
Dim myPanel As New RadPanelBar()
myPanel.ItemsSource = myListDataSource

By default, the string values from the items source collection will be assigned to the Header property of each RadPanelBarItem in the RadPanleBar control you are populating.

In case you want to display (in the item headers) a specific property of an object in a source collection, you can use the DisplayMemberPath property of RadPanelBar. You should set DisplayMemberPath to the name of the property you want to be displayed in the item header, like so:

C#

public partial class Example : UserControl
{
    public Example()
    {
        InitializeComponent();
        List<SourceCollection> sourceCollection = new List<SourceCollection>();
        sourceCollection.Add(new SourceCollection());
        sourceCollection.Add(new SourceCollection());
        sourceCollection.Add(new SourceCollection());
        RadPanelBar myPanel = new RadPanelBar();
        myPanel.ItemsSource = sourceCollection;
        myPanel.DisplayMemberPath = "Text";

    }
}
public class SourceCollection
{
    private Random number;
    public SourceCollection()
    {
        number = new Random((int)DateTime.Now.Ticks);
    }
    public DateTime Time
    {
        get { return DateTime.Now; }
    }
    public int Number
    {
        get
        {
            return number.Next(0, 1000);
        }
    }
    public string Text
    {
        get
        {
            // Return a string of 8 random characters from A to Z
            System.Text.StringBuilder randomText = new System.Text.StringBuilder(8);
            for (int i = 0; i < 8; i++)
            {
                randomText.Append((char)(65 + (number.NextDouble() * 25)));
            }
            return randomText.ToString();
        }
    }
}

VB.NET

Partial Public Class Example
    Inherits UserControl
    Public Sub New()
        InitializeComponent()

        Dim sourceCollection As New List(Of SourceCollection)()

        sourceCollection.Add(New SourceCollection())
        sourceCollection.Add(New SourceCollection())
        sourceCollection.Add(New SourceCollection())
        Dim myPanel As New RadPanelBar()
        myPanel.ItemsSource = sourceCollection

        myPanel.DisplayMemberPath = "Text"
    End Sub
End Class
Public Class SourceCollection
    Private m_number As Random
    Public Sub New()
        m_number = New Random(CInt(DateTime.Now.Ticks))
    End Sub
    Public ReadOnly Property Time() As DateTime
        Get
            Return DateTime.Now
        End Get
    End Property
    Public ReadOnly Property Number() As Integer
        Get
            Return m_number.[Next](0, 1000)
        End Get
    End Property
    Public ReadOnly Property Text() As String
        Get
            'Return a string of 8 random characters from A to Z'
            Dim randomText As New System.Text.StringBuilder(8)
            For i As Integer = 0 To 7
                randomText.Append(ChrW(65 + (m_number.NextDouble() * 25)))
            Next
            Return randomText.ToString()
        End Get
    End Property
End Class