Dataview sort method is not sorting ....

S

Sarah Smith

hello,

I am using the DataView object to sort records from a dataset.

I use this code to read from the dataview to 2 text boxes on screen:

Me.txtName.Text = myDataView.Table.Rows(nRecord).Item(0).ToString

Me.txtTEL.Text = myDataView.Table.Rows(nRecord).Item(1).ToString



nRecord is updated by navigation buttons. The columns referenced in
Item(0) and Item(1) are "Name" and "Tel"

After creating the DataView, I sort the data using myDataView.Sort =
"Name ASC" or myDataView.Sort = "Name, Tel ASC"

When I use the navigation buttons, the records still appear in the
same order that they were added to the underlying DataSet. (Not
sorted).

But .... if I attach a Data grid to the DataView, then the records
appear sorted and correct.

I've also tried like this:
Me.txtName.Text =
myDataView.Table.DefaultView.Item(nRecord).Row.Item(0).ToString()
Me.txtTEL.Text =
myDataView.Table.DefaultView.Item(nRecord).Row.Item(1).ToString()


Can anyone see something obvious I'm doing wrong?

SS.
 
P

Peter Foot [MVP]

It appears you are binding to the underlying table, not the dataview itself,
therefore navigation between the rows will of course be in the order of the
table (not the view).

Try this instead:-
Me.txtName.Text = myDataView(nRecord).Item(0).ToString()

Peter
 
S

Sarah Smith

Thanks a lot Peter, that did the trick, but I had to change it to
named columns like this:

Me.txtTEL.Text = myDataView(nRecord).Item("Tel").ToString

..... because I have Option Strict turned on.

Do you think it will make a difference in performance if I turn off
Option Strict and used indexing instead?

Thanks,

SS.
 
W

William Ryan eMVP

Sarah:

In general you'll want to use Index based lookups for performance, however,
this only affects code where you are using the dataview/datatable and with
small numbers of records, the performance difference is very small.
However, Option Strict should be left on b/c if you turn it off, you'll
probably start injecting implicit type conversions and Options Slow will be
on. I'd go ahead and just use the String based lookup on this and leave
Option Strict on.

HTH,

Bill
 
S

Sarah Smith

Will do. Thanks for the advice.

SS.


Sarah:

In general you'll want to use Index based lookups for performance, however,
this only affects code where you are using the dataview/datatable and with
small numbers of records, the performance difference is very small.
However, Option Strict should be left on b/c if you turn it off, you'll
probably start injecting implicit type conversions and Options Slow will be
on. I'd go ahead and just use the String based lookup on this and leave
Option Strict on.

HTH,

Bill
 

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

Similar Threads


Top