By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,168 Members | 2,599 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,168 IT Pros & Developers. It's quick & easy.

DataView/DataGrid Sort

P: n/a
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.
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"Gene Hubert" <gw******@hotmail.com> wrote in message
news:7e**************************@posting.google.c om...
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
Nov 21 '05 #2

P: n/a
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

"Andy Becker" <x@x.com> wrote in message news:<Or*************@TK2MSFTNGP10.phx.gbl>...
"Gene Hubert" <gw******@hotmail.com> wrote in message
news:7e**************************@posting.google.c om...
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

Nov 21 '05 #3

P: n/a
"Gene Hubert" <gw******@hotmail.com> wrote in message
news:7e**************************@posting.google.c om...
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
Nov 21 '05 #4

P: n/a
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.

"Andy Becker" <x@x.com> wrote in message news:<OS**************@TK2MSFTNGP11.phx.gbl>...
"Gene Hubert" <gw******@hotmail.com> wrote in message
news:7e**************************@posting.google.c om...
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

Nov 21 '05 #5

P: n/a
"Gene Hubert" <gw******@hotmail.com> wrote in message
news:7e**************************@posting.google.c om...
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
Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.