Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
350
I need VB.Net sample of binding xamTimeLine to a database DataSource
posted

Version:WPF DV 2010.3

My database table gets 4 fields:ID,theDate,TheDuration,theTitle,and theDetails.After adding a new datasource of this database(table) in VisualStudio 2010,how to binde xamTimeLine(display DateTime data) to it.I need a VB.NET sample code.

Thanks.

  • 17605
    Verified Answer
    posted

    You need to convert your DataTable to List of custom objects and bind them to the Timeline series. Try using this code:

     

    Partial Public Class MainWindow
        Inherits Window
        Public Sub New()
            InitializeComponent()

            Dim dataTable As New DataTable()

            dataTable.Columns.Add("ID"GetType(Integer))
            dataTable.Columns.Add("Date"GetType(DateTime))
            dataTable.Columns.Add("Duration"GetType(TimeSpan))
            dataTable.Columns.Add("Title"GetType(String))
            dataTable.Columns.Add("Details"GetType(String))

            dataTable.Rows.Add(1, DateTime.Now, New TimeSpan(1, 0, 0), "Title 1""Details 1")
            dataTable.Rows.Add(2, DateTime.Now.AddHours(3), New TimeSpan(1, 0, 0), "Title 2""Details 2")

            Dim series As New DateTimeSeries()

            series.DataMapping = "Time=Date;Title=Title;Duration=Duration;Details=Details"
            series.DataSource = ConvertDataTable(dataTable)

            Me.Timeline.Series.Add(series)
        End Sub

        Private Function ConvertDataTable(ByVal dataTable As DataTable) As List(Of TimelineData)
            Dim data As New List(Of TimelineData)()

            For Each row As DataRow In dataTable.Rows
                Dim item As New TimelineData()
                item.[Date] = DirectCast(row("Date"), DateTime)
                item.Duration = DirectCast(row("Duration"), TimeSpan)
                item.Title = DirectCast(row("Title"), String)
                item.Details = DirectCast(row("Details"), String)

                data.Add(item)
            Next

            Return data
        End Function
    End Class

    Public Class TimelineData
        Public Property [Date]() As DateTime
            Get
                Return m_Date
            End Get
            Set(ByVal value As DateTime)
                m_Date = Value
            End Set
        End Property
        Private m_Date As DateTime
        Public Property Duration() As TimeSpan
            Get
                Return m_Duration
            End Get
            Set(ByVal value As TimeSpan)
                m_Duration = Value
            End Set
        End Property
        Private m_Duration As TimeSpan

        Public Property Title() As String
            Get
                Return m_Title
            End Get
            Set(ByVal value As String)
                m_Title = Value
            End Set
        End Property
        Private m_Title As String
        Public Property Details() As String
            Get
                Return m_Details
            End Get
            Set(ByVal value As String)
                m_Details = Value
            End Set
        End Property
        Private m_Details As String
    End Class

    
    

     

     

    You can also look at:

    http://help.infragistics.com/NetAdvantage/WPFDV/2010.3/CLR4.0/?page=SL_DV_xamWebTimeline_Binding_to_Data_with_xamTimeline.html