Sorting not working

pachjo

Well-known member
Joined
Dec 12, 2006
Messages
370
Programming Experience
10+
Hi,

I have a tableadapter with a .Fill method that sorts on id and date

I have a datagridview that has a bindingsource to the table

The column collection for the id and date columns are set to autosort

When I add a new row, update and fill the table the dataview is not sorted as follows:

1 01/05/2007
2 02/05/2007
3 29/04/2007

instead of

3 29/04/2007
1 01/05/2007
2 02/05/2007

The tableadapter clears the table before fill and the fill gets the data sorted

What have I missed??
 
huh? Don't understand the full question.

What are you trying to sort on? If you're ID is a primary key it's obviously going to sort on that asc.

If you want to sort by date then you need to add it to your SQL query

ORDER BY Date ASC or ORDER BY Date DESC
 
Hi,

I found this out :eek: but still getting stuffed by this?

The sql now orders by date, id

When I preview the data I get the correct output, but in the datagridiew it is still wrong.

Example showing correct preview in dataset designer

id date

1 30/05/2007 other data.....
4 30/05/2007 other data.....
2 31/05/2007 other data.....
3 01/06/2007 other data.....

Example showing incorrect datgridview display

id date

4 30/05/2007 other data.....
1 30/05/2007 other data.....
2 31/05/2007 other data.....
3 01/06/2007 other data.....

The id is not visible on the datagridview (shown here to help)
 
Sounds like your grid has something set.

drop another grid on your form, drop the dataTable onto that new grid and see if you get expected results (in theory you should).

The grid should show exactly the same data in the same order it appears in the datatable query, unless you set sorting and other options on the grid itself.

Also, have you updated all queries on that datatable to sort the correct way?
 
the dates are being sorted as strings
whats the point of sorting anything else, if an ID field is being sorted first?
youre sorting twice - first the TA gets the db to return rows in a sorted order, then your grid goes and sorts them again

keep it simpler
 
Back
Top