In my project, at some point I tend to load all rows in my DataSet and add them to my FlowLayoutPanel in order of their "Time" Item. This is what I'm trying to do but I need the controls to be added first if their "Time" value are the oldest :

For i=1 to DataSet.Tables("myTable").Rows.Count
 Dim Row as Datarow = DataSet.Tables("myTable").Select("ID = " & i)
 Dim Time as Date = Row.Item("Time")
 Dim NewLabel as Label
 NewLabel.text = Time.ToString()
 FlowLayoutPanel.Controls.Add(newLabel)
Next

How do I do that ?

Have you considered to just sort the datatable by "Time" ?
If this is an option for you then check out this link: Click Here

Hi,
If you can't sort the table directly, you should be able to make a DataView which you should then be able to sort.

something like this should work:

Dim NewLabel as Label
NewLabel.Text = Date.Now.ToString
For i=1 to DataSet.Tables("myTable").Rows.Count
    Dim Row as Datarow = DataSet.Tables("myTable").Select("ID = " & i)
    Dim Time as Date = Row.Item("Time")
    If(Time < Date.Parse(NewLabel.Text)) Then
        NewLabel.text = Time.ToString()
    End If
Next
FlowLayoutPanel.Controls.Add(NewLabel)
I think it could be help you
Dim timeOrderedRows = From row in DataSet.Tables("myTable")
                      Order By row.Field(Of Date)("Time")
For Each row As DataRow In timeOrderedRows
    Dim Time as Date = row.Field(Of Date)("Time")
    Dim Label as New Label
    Label.text = Time.ToString()
    FlowLayoutPanel.Controls.Add(Label)
Next
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.