Sort DataGridView

J

joey.powell

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.Ascending)
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.
 
D

DBC User

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
 
S

Shawn Wildermuth (C# MVP)

Hello (e-mail address removed),

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
 

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