DataView sort

If i put the dataview as a datasource of a datagrid the sorting works fine.

If i load the records one by one from the dataview the position of these records is the same as before the sort.

How can i avoid this



Answer this question

DataView sort

  • CWORRELLSTER

    I'm sure you;'ve already figures this out, but I could not get my sort to work at all.

    I just found the answer, and decided to post it so all others could find a solution to the dataview sort not sorting when your not binding to any datagrid. Cause I searched for hours trying to figure this out.

    How to access the row of the sorted dataview.

    dv.table is the unsorted

    while

    dv(i).Row gives you the row of the sorted set.

    dv..Table.Rows(i).Item("someword") returns from the none sorted set.

    Dim i As Int32

    Dim dv As DataView

    Try

    'use dataview to sort rank on results

    dv = New DataView(mdtRankedResults.DefaultView.Table)

    dv.Sort = "Rank DESC"

    For i = 0 To dv.Table.Rows.Count - 1

    If mblnResults = True And dv(i).Row.Item("section") = 1 Then

    ResultsEventsShow(dv(i).Row)

    End If

    If mblnResults = True And dv(i).Row.Item("section") = 2 Then

    ResultsNewsShow(dv(i).Row)

    End If

    Next


  • SarahH

    Hi

    I think you can use DataView. But, you should fetch data through dataview.

    If you are not using dataview as datasource your don't need to worry about dataview.

    In my Idea DataView has to work if you are fetching data through dataview not directly from DataTable



  • R.K.S.

    Not sure, but:

    Don't access the dataview directly, if you want to access the rows as the datagrid sees them.

    Go through the currencymanager' List object


  • Michael_Guinto

    Further to Doug's remarks, the DataView is a collection of DataRowView objects. The order and availabilty of DataRowView objects in the DataView depends on the Sort, RowFilter, and/or RowStateFilter property values. The underlying DataTable object, however, maintains the original order that the records were in when they were retrieved from the database. To change the order within the DataTable itself, it will be necessary to specify a WHERE and/or ORDER BY clause in the SELECT statement that retrieves the data from the database.

  • oriticol

    Sounds like you're trying to actually sort the database...

    A Dataview is simply that - a "view" of the same data.

    Dataviews allow you to present a set of data to the user in various ways: sorted or filtered. You can assign a dataview to a datagrid, then make the column headers perform different sorts when you click them. You can also set the filter properties to only show certain records.

    The dataview shouldn't change unless it loses scope or you change the properties...


  • DataView sort