move rows in a dataview

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sam

    move rows in a dataview

    Hi,
    How can I move a row in my dataview to the first position ?

    Thx

  • Ken Tucker [MVP]

    #2
    Re: move rows in a dataview

    Hi,

    Sorting the dataview will reorder the records. You might have to
    add a column to the datatable for sorting


    Dim strConn As String
    Dim ds As New DataSet
    Dim strSQL As String
    Dim daEmployees As OleDbDataAdapte r
    Dim conn As OleDbConnection
    strConn = "Provider = Microsoft.Jet.O LEDB.4.0;"
    strConn &= "Data Source = Northwind.mdb;"

    conn = New OleDbConnection (strConn)
    da = New OleDbDataAdapte r("Select * From Categories", conn)
    da.Fill(ds, "Categories ")

    Dim dcSort As New DataColumn("Fir st", GetType(Integer ))
    ds.Tables("Cate gories").Column s.Add(dcSort)

    Trace.WriteLine ("Before sort")
    Dim dv As New DataView(ds.Tab les("Categories "))
    For Each drvCategories As DataRowView In dv
    Trace.WriteLine (drvCategories. Item("Descripti on"))
    Next

    For Each drvCategories As DataRowView In dv
    drvCategories.I tem("First") = 1
    Next

    dv.Item(4).Item ("First") = 0
    dv.Sort = "First"
    Trace.WriteLine ("After sort")
    For Each drvCategories As DataRowView In dv
    Trace.WriteLine (drvCategories. Item("Descripti on"))
    Next


    Ken
    ---------------------


    "Sam" <samuel.berthel ot@voila.fr> wrote in message
    news:1119869864 .674019.250790@ g49g2000cwa.goo glegroups.com.. .
    Hi,
    How can I move a row in my dataview to the first position ?

    Thx


    Comment

    Working...