DataView does not recognize 'DESC'

D

dbuchanan

My code specifies a descending sort, but when my form opens the
datagrid is sorted ascending. However the controls that are bound to
the datagrid recognize the row selection *as if* the rows were sorted
descending. For example: If I select the first row, I get the last row
instead.

=== my code snipit ===

Private bmb As BindingManagerBase

Private Sub SetBindings()

Dim dt As DataTable = dataSet1.tblJob
Dim dView As New DataView

dView.Table = dt
dView.Sort = "JobNumber DESC" '<< note the 'DESC'

DataGrid1.DataSource = Nothing '<< see below for why this is here.
DataGrid1.DataSource = dView

'Controls
lblpkJobId.DataBindings.Add("Text", dView, "pkJobId")
txtJobNumber.DataBindings.Add("Text", dView, "JobNumber")
cboCustomerName.DataBindings.Add("Text", dView, "CustomerName")
txtJobDescription.DataBindings.Add("Text", dView, "JobDescription")

bmb = Me.BindingContext(dataSet1.Tables(currentTable))

End Sub
=== end of code ===

why is this????? Help!




Extra information to show the code works :
BTW I have other buttons that execute other code that sorts in other
ways and a button that links back to the method shown above. If I click
those buttons to sort in other ways and then click the button that
executes the code above then the sort is descending as it should be.
Strange.
The line containing "DataGrid1.DataSource = Nothing" is present to
"clean up after the previous sort. Another method not shown clears the
databinding of the controls just before the above method above is
executed.
 
C

Cor Ligthert

Dough,

I don't see it, however maybe we can start to make your code more simple and
use the defaultview in every table and not an extra dataview.
Private bmb As BindingManagerBase

Private Sub SetBindings()

Dim dt As DataTable = dataSet1.tblJob

Dim dView as DataView = dt.defaultview
dView.Sort = "JobNumber DESC" '<< note the 'DESC'
DataGrid1.DataSource = Nothing '<< see below for why this is here.
DataGrid1.DataSource = dView

However I would not see from the code you supplied why it would not work.
(However I can over see as well something of course).

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top