New to Telerik UI for WinForms? Download free 30-day trial

Data Binding

You can directly bind your preferred series to your data, the currently supported data sources are:

  • IList interface for one-dimensional arrays.

  • IListSource interface (like DataTable and DataSet classes).

  • IBindingList interface. For example the generic BindingList class.

  • IBindingListView interface. For example BindingSource class.

To bind the series you need to set the ValueMember property. The following example demonstrates this.

Bind Series to a DataTable

DataTable table;
public void AddBoundSeries()
{
    table = new DataTable();
    table.Columns.Add("Value", typeof(double));
    table.Rows.Add(1);
    table.Rows.Add(-3);
    table.Rows.Add(5);
    table.Rows.Add(1);
    table.Rows.Add(6);
    table.Rows.Add(-1);
    table.Rows.Add(3);
    table.Rows.Add(-5);
    table.Rows.Add(1);
    table.Rows.Add(6);
    SparkLineSeries lineSeries = new SparkLineSeries();
    lineSeries.ValueMember = "Value";
    lineSeries.DataSource = table;
    lineSeries.ShowMarkers = true;
    lineSeries.ShowHighPointIndicator = true;
    lineSeries.ShowLowPointIndicator = true;
    radSparkline1.Series = lineSeries;
}

Private table As DataTable
Public Sub AddBoundSeries()
    table = New DataTable()
    table.Columns.Add("Value", GetType(Double))
    table.Rows.Add(1)
    table.Rows.Add(-3)
    table.Rows.Add(5)
    table.Rows.Add(1)
    table.Rows.Add(6)
    table.Rows.Add(-1)
    table.Rows.Add(3)
    table.Rows.Add(-5)
    table.Rows.Add(1)
    table.Rows.Add(6)
    Dim lineSeries As New SparkLineSeries()
    lineSeries.ValueMember = "Value"
    lineSeries.DataSource = table
    lineSeries.ShowMarkers = True
    lineSeries.ShowHighPointIndicator = True
    lineSeries.ShowLowPointIndicator = True
    radSparkline1.Series = lineSeries
End Sub

The bellow image show the result from the above code.

WinForms RadSparkline Data Binding DataTable

In this article