Discussion:
A DataGridView Walks Into a Bar...And Says "Sort Me, I Dare You...I Won't Stay That Way..."
(too old to reply)
Patrick A
2010-03-26 03:05:17 UTC
Permalink
All,

When I save datagridview record changes, should the current sort
column and order save?


I have a datagridview I placed onto a form, and it is "fed" without
any sorting from a DB (bound datasource).


Changes to any cell in the datagridview save just fine, but if the
user sorts the datagridview by clicking on a column (as they like to
do), that does not save/update the DB. (And does not persist from
session to session.)

Is this by design?

If not, any suggstions as to what to verify or enable to make it
work?

If so, any suggestions as to how I might code around this? Users want
sort to stay sorted, and some other parts of my app re-purpose the
data, which should also appear in the sorted order.

Thanks,

Patrick
PvdG42
2010-03-26 14:28:55 UTC
Permalink
Post by Patrick A
All,
When I save datagridview record changes, should the current sort
column and order save?
I have a datagridview I placed onto a form, and it is "fed" without
any sorting from a DB (bound datasource).
Changes to any cell in the datagridview save just fine, but if the
user sorts the datagridview by clicking on a column (as they like to
do), that does not save/update the DB. (And does not persist from
session to session.)
Is this by design?
If not, any suggstions as to what to verify or enable to make it
work?
If so, any suggestions as to how I might code around this? Users want
sort to stay sorted, and some other parts of my app re-purpose the
data, which should also appear in the sorted order.
Thanks,
Patrick
Not "sorting" the table(s) from which the DataGridView is populated is by
design. You, as the app developer, have no control over the order of rows in
a given table. That is handled by the DBMS. If you want the user's sort
selection in the control to stick, you'll need to write the necessary code
to, first, record the user's choice and, second, subsequently use a
parameterized query with an added Order BY clause to produce the desired
sort when the control is repopulated.
Patrick A
2010-03-26 17:57:32 UTC
Permalink
Thanks, PvdG,

Someone else suggested saving the columnsort and columnsortorder and
using them to set the sort in the DataGridView through code, not
SQL.

Any thoughts on if one method is "better" than the other?

Patick
Post by PvdG42
Post by Patrick A
All,
When I save datagridview record changes, should the current sort
column and order save?
I have a datagridview I placed onto a form, and it is "fed" without
any sorting from a DB (bound datasource).
Changes to any cell in the datagridview save just fine, but if the
user sorts the datagridview by clicking on a column (as they like to
do), that does not save/update the DB.  (And does not persist from
session to session.)
Is this by design?
If not, any suggstions as to what to verify or enable to make it
work?
If so, any suggestions as to how I might code around this?  Users want
sort to stay sorted, and some other parts of my app re-purpose the
data, which should also appear in the sorted order.
Thanks,
Patrick
Not "sorting" the table(s) from which the DataGridView is populated is by
design. You, as the app developer, have no control over the order of rows in
a given table. That is handled by the DBMS. If you want the user's sort
selection in the control to stick, you'll need to write the necessary code
to, first, record the user's choice and, second, subsequently use a
parameterized query with an added Order BY clause to produce the desired
sort when the control is repopulated.- Hide quoted text -
- Show quoted text -
Loading...