Sorting a DataView

whorian

New member
Joined
Oct 4, 2008
Messages
1
Programming Experience
5-10
Hello.

I am trying to sort a DataView and the Sort property does not work. It just doesn't sort anything!

Here's the code- it is placed in the SortCommand event of the DataGrid (pss.. I am using framework v1.1 and VS2003 - Datagrid was build using designer)

Private Sub grilleAffichage_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles grilleAffichage.SortCommand

VB.NET:
    Me.dsAffichage.Tables("Formulaire").DefaultView.Sort = "NomEmplInterv Asc" ' The column exists and the DataSet has values. 
    grilleAffichage.DataSource = Me.dsAffichage.Tables("Formulaire").DefaultView
    grilleAffichage.DataBind()
And this code has proven me that the View is unsorted:
VB.NET:
For each dr in Me.dsAffichage.Tables("Formulaire").DefaultView.Table.Rows
     concat = concat & CType(dr("NomEmplInterv"), String) & vbNewLine
    Next

Oh and yes, the DataGrid has AllowSorting to True.

Any ideas?
Thanks
 
'assuming that your datasources and dataview has already been set up

dv.sort = "dataproperty1, dataproperty2, ... ASC"

'this will sort the specified dataproperties ascending (use DESC to sort descending)
 
FYI,

Me.dsAffichage.Tables("Formulaire").DefaultView.Table.Rows

Is referring to the underlying datatable its the same as

Me.dsAffichage.Tables("Formulaire").Rows

So that proves nothing... Put a breakpoint at
VB.NET:
For each dr in Me.dsAffichage.Tables("Formulaire").DefaultView.Table.Rows
. When the breakpoint is reached, highlight
VB.NET:
Me.dsAffichage.Tables("Formulaire").DefaultView
, right click and click on 'quick view'.. Click on the magnifying class. Theres your table.
 
Are you even using a DataView? I see a DataSet and DataGrid but don't see any DataView mentioned in your coding example.

VB.NET:
    [COLOR="Blue"]Private Sub[/COLOR] SortDataView()

        [COLOR="Green"]' Get data from dataset.table or DataTable and put into a DataView[/COLOR]
        [COLOR="blue"]Dim [/COLOR]view [COLOR="blue"]As [/COLOR]DataView = Me.dsAffichage.Tables("Formulaire").DefaultView

        [COLOR="green"]' Sort by column specified[/COLOR]
        view.Sort = "[COLOR="Red"]NomEmplInterv ASC[/COLOR]"

    [COLOR="blue"]End Sub[/COLOR]
 

Latest posts

Back
Top