473,396 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

DataView/DataGrid Sort

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
5 2213
"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
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
"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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Bruce Pullum | last post by:
I have a datagrid that I am using a DataView with. All works great for the sorting of the columns. However, after I sort the column, and then try and select a data row to edit, the row selected...
4
by: Martin Schmid | last post by:
I am trying to implement a DataView for a DataGrid so I can sort at runtime by clicking on column headers. My initial page load works... it displays the data However, when I click a column...
1
by: Rakesh | last post by:
Using the BindingContext we will be able to find the actual position of the row selected in a DataView (regardless of the sort used). What I want to do is exactly the reverse. That is, I know...
0
by: Michał Januszczyk | last post by:
Is it possible somehow to retreive {data Key Value} based on clicked {datagrid item index} ? Now i'm trying to do this in the following way, but with no effect. Now, Instead of getting value...
1
by: troyblakely | last post by:
I am having trouble sorting a datagrid. I have read numerous posts on this and other lists, and tried most of the suggestions, but none of them have worked for me yet. I populate a dataset from two...
13
by: Steve | last post by:
I have a form with a dataset and a datagrid. I created a dataview on this dataset. When the user modifies the datagrid, I look up this record in the dataview to make sure it is unique. Here is...
4
by: Aaron Smith | last post by:
Dim dv As DataView = New DataView(FacilitiesDS1.Facilities, "", "ID ASC", DataViewRowState.CurrentRows) Dim iPos As Integer = dv.Find(dr.Item("ID")) Me.BindingContext(FacilitiesDS1,...
5
by: enceladus311 | last post by:
I'm trying to find a way to keep from having to fill a DataView after every PostBack to a page. Basically, the design is that I have a DataView that I fill, which I then set as the DataSource to a...
0
by: Nathan Franklin | last post by:
Hello Guys, I have been trying to work this our for so long, but I just can't seem to find the answer. I am loading a datatable from a an access database using an oledbdataadapter. I then...
10
by: babis | last post by:
I work with .NET2003 C# windows form application, i add a datagrid in my form like this: dataGridProduct.DataSource = dataViewProduct; I also make the allowSort property of the datagrid...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.