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 ?

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)

Edited 3 Years Ago by tinstaafl

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
This article has been dead for over six months. Start a new discussion instead.