DataView/DataGrid Sort

G

Gene Hubert

I'm using the DefaultView from the Datasource for a DataGrid to
present the data in a particular order. It seems that sorting in this
way is an "Active Sort", as is the default sort that is provided by
clicking on a column header. By "Active Sort", I mean that editing a
value in a sorted column may cause the record to be moved to maintain
the sort order.

Is there an efficient way to present the data in a given order but not
have it be an "Active Sort." That is, I don't want records jumping
around to different places because the value in a sorted column has
been edited. I also need to allow a user to select which column the
grid is sorted on by clicking on the column header.

Thanks Much,
Gene H.
 
A

Andy Becker

Gene Hubert said:
Is there an efficient way to present the data in a given order but not
have it be an "Active Sort." That is, I don't want records jumping
around to different places because the value in a sorted column has
been edited. I also need to allow a user to select which column the
grid is sorted on by clicking on the column header.

Thanks Much,
Gene H.

Only to feed it a data source which is pre-sorted as desired. The jumping
can't be prevented once a column header has been clicked, though, and some
data in that column edited.

The DataGrid should allow you to click on column headings and sort... The
property is AllowSorting, but I can't recall the default value at the
moment.

Does this help any?

Best Regards,

Andy
 
G

Gene Hubert

Thanks Andy. That 'bout what I figured.

Is there a way to bulk move records from one datatable to another?
Here's what I'm doing now, a record at a time...

Dim dt, dtSort As DataTable
Dim dv As DataView
Dim dr As DataRow

....do a bunch of stuff to load dt...

dv = dt.DefaultView 'set initial display order
dv.Sort = "Sort ASC, Name ASC"

dtSort = dt.Clone 'copy datatable structure
dtSort.DefaultView.Sort = Nothing 'remove the sort

For Each dr In dt.Select 'move the data
dtSort.ImportRow(dr)
Next

FileList.DataSource = dtSort
 
A

Andy Becker

Gene Hubert said:
Thanks Andy. That 'bout what I figured.

Is there a way to bulk move records from one datatable to another?

I haven't ever used it (yet), but it looks like you can just use
DataTable.Copy. In your particular case, it may be approriate to sort the
copy instead of the other way around, to leave an unsorted DefaultView
behind... But I don't know much about the application. :)

Best Regards,

Andy
 
G

Gene Hubert

I couldn't get it to work using datatable.copy. It seems that if the
datatable has data in it, and then you change the sort property, the
data is immediately reshuffled.

If you copy the data using datatable.copy, the sort property of the
target datatable is set to empty string, but the data in it does not
present in the sort order of the source datatable used in the copy.

Gene H.
 
A

Andy Becker

Gene Hubert said:
I couldn't get it to work using datatable.copy. It seems that if the
datatable has data in it, and then you change the sort property, the
data is immediately reshuffled.

If you copy the data using datatable.copy, the sort property of the
target datatable is set to empty string, but the data in it does not
present in the sort order of the source datatable used in the copy.

Gene H.

I don't think I was very clear in expressing my thoughts. If it is still of
use to you, the idea was to pull rows into a datatable with the required
sort already present, i.e. an "order by" clause. Then copy this to another
datatable and sort as needed.

Are you trying to make a copy of the row in their natural (unsorted) order?

Best Regards,

Andy
 

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