473,386 Members | 1,798 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,386 software developers and data experts.

Sort DataGridView

I have a datagridview where I set its "DataSource" property to a
DataSet and its "DataMember" property to a table within the DataSet. I
need for the DataGridView to "sort" through the contents of the DataSet
as it binds. Can I specify a column on the DataSet that, sorted, will
control the order of the rows in the datagridview? It seems to just
parse over the data in the DataSet and bind to it, without my being
able to control the order that it acquires the records.

I can call myDataGridView.Sort(myColumn,ListSortDirection.Asc ending)
after the bind, but the indeces of the datagridview rows do not get
changed when the rows are reordered. To be able to use "Move Up" and
"Move Down" buttons, I need for the indeces to match the order of
values of a certain column in the DataSet (i.e. 0, 1, 2). But the
values are not stored in order (i.e. 0,1,2) etc in that DataSet. They
may be random.

Jul 27 '06 #1
3 11911
Hi Joey,

I had the same problem and I did a post on this group and I got an
answer saying you have write methods to handle it manually.
What I did is to make a key and as I move up and down, I use the key to
identify the corresponding row in the dataset for further processing.

Thanks.
I associate a datasource to datagrid and then allow the user to sort
the data. I keep the row
jo*********@topscene.com wrote:
I have a datagridview where I set its "DataSource" property to a
DataSet and its "DataMember" property to a table within the DataSet. I
need for the DataGridView to "sort" through the contents of the DataSet
as it binds. Can I specify a column on the DataSet that, sorted, will
control the order of the rows in the datagridview? It seems to just
parse over the data in the DataSet and bind to it, without my being
able to control the order that it acquires the records.

I can call myDataGridView.Sort(myColumn,ListSortDirection.Asc ending)
after the bind, but the indeces of the datagridview rows do not get
changed when the rows are reordered. To be able to use "Move Up" and
"Move Down" buttons, I need for the indeces to match the order of
values of a certain column in the DataSet (i.e. 0, 1, 2). But the
values are not stored in order (i.e. 0,1,2) etc in that DataSet. They
may be random.
Jul 27 '06 #2
Hello jo*********@topscene.com,

The real solution here is to *not* bind tothe the DataSet, but to create
a DataView.
Thanks,
Shawn Wildermuth
Speaker, Author and C# MVP
http://adoguy.com
I have a datagridview where I set its "DataSource" property to a
DataSet and its "DataMember" property to a table within the DataSet. I
need for the DataGridView to "sort" through the contents of the
DataSet as it binds. Can I specify a column on the DataSet that,
sorted, will control the order of the rows in the datagridview? It
seems to just parse over the data in the DataSet and bind to it,
without my being able to control the order that it acquires the
records.

I can call myDataGridView.Sort(myColumn,ListSortDirection.Asc ending)
after the bind, but the indeces of the datagridview rows do not get
changed when the rows are reordered. To be able to use "Move Up" and
"Move Down" buttons, I need for the indeces to match the order of
values of a certain column in the DataSet (i.e. 0, 1, 2). But the
values are not stored in order (i.e. 0,1,2) etc in that DataSet. They
may be random.

Jul 27 '06 #3
Thanks, Shawn. That got it.

Shawn Wildermuth (C# MVP) wrote:
Hello jo*********@topscene.com,

The real solution here is to *not* bind tothe the DataSet, but to create
a DataView.
Thanks,
Shawn Wildermuth
Speaker, Author and C# MVP
http://adoguy.com
I have a datagridview where I set its "DataSource" property to a
DataSet and its "DataMember" property to a table within the DataSet. I
need for the DataGridView to "sort" through the contents of the
DataSet as it binds. Can I specify a column on the DataSet that,
sorted, will control the order of the rows in the datagridview? It
seems to just parse over the data in the DataSet and bind to it,
without my being able to control the order that it acquires the
records.

I can call myDataGridView.Sort(myColumn,ListSortDirection.Asc ending)
after the bind, but the indeces of the datagridview rows do not get
changed when the rows are reordered. To be able to use "Move Up" and
"Move Down" buttons, I need for the indeces to match the order of
values of a certain column in the DataSet (i.e. 0, 1, 2). But the
values are not stored in order (i.e. 0,1,2) etc in that DataSet. They
may be random.
Jul 28 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: milk-jam | last post by:
I'm trying to set my datagridview so that the first row will be left blank and to use it as a filtering filed for the datagridview. Until now I was using 2 datagridview the upper one with a header...
0
by: inpuarg | last post by:
Is it possible to sort datagridview programmatically in virtualmode ? ..Sort() method isn 't working ?
1
by: sapkal.manish | last post by:
Question : How can I find actual row position of DataTable in DataGridView when DataTable is sorted / My source code like this Private WithEvent dgvInwDet as new DataGridView Private...
4
by: Matt | last post by:
I have been searching all over the web for a way to sort a DataGridView based on the actual text being shown in a ComboBox column as opposed to the underlying value (an ID in this case). Can anyone...
2
by: tee | last post by:
Hi, How do i sort datagridview programmically, current i have the following code but i keep get the error saying "DataGridView control must be bound to an IBindingList object to be sorted.", ...
2
by: Rick | last post by:
VS 2005/Pro I'm using a DataGridView in a Windows form and allowing the user to sort the columns by clicking on the header column. Is there some method offered by the grid to return back to...
2
by: Claes Wedin | last post by:
Hi, We have a DataGridView and the user wants to be able to change the order on the rows by drag and drop. The best would be if a thick line showed where the row will be placed when moving over...
3
by: Frederik | last post by:
Hi group, I have a DataGridView that is mainly consisting of data bound columns. One column however is unbound. I'm not able to sort the grid on this column! Is that normal behaviour? If so,...
3
by: frenzy99 | last post by:
Can some one help me with this problem. I want to sort DataGridView based on the order in which values were added, not on the basis of any particular column, unlike the functionality provided by...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.