DataBinding

Data binding provides a way to bind the display of data in a RadListControl to a data source. Three properties control data binding:

  • The DataSource property specifies the source of the data to be bound.

  • The DisplayMember property specifies the particular data to be displayed in a RadListControl.

  • The ValueMember property specifies the particular data to be returned as the value of a RadListControl.

Data binding at design time

You can set the DataSource property at design time in the Properties window of Visual Studio.

  1. Select the DataSource property and click the drop-down arrow to display all existing data sources on the form.

  2. Click the Add Project Data Sourceā€¦ link and follow the instructions in the Data Source Configuration Wizard to add a data source to your project. You can use a single database table.

    Figure: 1 Setting the DataSource at Design time

    dropdown-and-listcontrol-listcontrol-populating-with-data-data-binding 001

  3. Afterwards, you need to specify the DisplayMember and ValueMember properties.

    Figure: 2 Setting the DisplayMember and ValueMember properties at Design time

    dropdown-and-listcontrol-listcontrol-populating-with-data-data-binding 002

    Figure: 3 RadListControl bound at Design time

    dropdown-and-listcontrol-listcontrol-populating-with-data-data-binding 003

Data binding at run time

public class Item
{
    public int Id { get; set; }
    public string Description { get; set; }
    public Item(int id, string description)
    {
        this.Id = id;
        this.Description = description;
    }
}
public void Bind()
{
    List<Item> items = new List<Item>();
    for (int i = 0; i < 10; i++)
    {
        items.Add(new Item(i, "Data" + i));
    }
    radListControl1.DataSource = items;
    radListControl1.DisplayMember = "Description";
    radListControl1.ValueMember = "Id";
}

Public Class Item
    Public Property Id() As Integer
    Public Property Description() As String
    Public Sub New(ByVal id As Integer, ByVal description As String)
        Me.Id = id
        Me.Description = description
    End Sub
End Class
Public Sub Bind()
    Dim items As New List(Of Item)()
    For i As Integer = 0 To 9
        items.Add(New Item(i, "Data" & i))
    Next i
    radListControl1.DataSource = items
    radListControl1.DisplayMember = "Description"
    radListControl1.ValueMember = "Id"
End Sub

Figure: 4 RadListControl bound at Run time

dropdown-and-listcontrol-listcontrol-populating-with-data-data-binding 004

See Also

In this article
Not finding the help you need? Improve this article