I have a DataTable that is bound to a DataGrid that displays a number of
selections from a product menu:

Item1 quantity price totalAmount
Item2 quantity price totalAmount
TAX - - - - - - - - - - totalAmount
TOTAL - - - - - - - - totalAmount

Each time the user makes a selection, the DataTable is updated and re-bound
to the DataGrid.

The problem is I need to keep the TAX and TOTAL rows as the last rows in the
DataTable so they appear at the bottom of the DataGrid. But the only way I
know how to do this is to delete the rows every time the user makes a
selection from the product menu, then recalculate the order, and lastly
reinsert the rows in the DataTable (otherwise the user's most recently
selected product is the last row in the DataTable and appears at the bottom
of the DataGrid).

Is there a way to re-order the rows rather than deleting and re-inserting
every time? Is there some way to tell the data table that the Total row
should be the last row in the table, and the Tax row second-to-last? That
way I could just overwrite the value in those rows rather than deleting and
re-inserting after each time the users selects another item.

Thanks in advance.

Re: Can rows be ordered in a datatable? by Mark

Mark
Sat Jul 30 14:07:36 CDT 2005

"deko" <deko@nospam.com> wrote in message
news:E-mdnT5nx86rKXbfRVn-tg@comcast.com...

> Thanks in advance.

http://www.knowdotnet.com/articles/dataviewsort.html



Re: Can rows be ordered in a datatable? by Robbe

Robbe
Sat Jul 30 15:19:02 CDT 2005

The .Select method has arguments for the ORDER BY clause

--
2004 and 2005 Microsoft MVP C#
Robbe Morris
http://www.masterado.net

Earn $$$ money answering .NET Framework
messageboard posts at EggHeadCafe.com.
http://www.eggheadcafe.com/forums/merit.asp



"deko" <deko@nospam.com> wrote in message
news:E-mdnT5nx86rKXbfRVn-tg@comcast.com...
>I have a DataTable that is bound to a DataGrid that displays a number of
>selections from a product menu:
>
> Item1 quantity price totalAmount
> Item2 quantity price totalAmount
> TAX - - - - - - - - - - totalAmount
> TOTAL - - - - - - - - totalAmount
>
> Each time the user makes a selection, the DataTable is updated and
> re-bound to the DataGrid.
>
> The problem is I need to keep the TAX and TOTAL rows as the last rows in
> the DataTable so they appear at the bottom of the DataGrid. But the only
> way I know how to do this is to delete the rows every time the user makes
> a selection from the product menu, then recalculate the order, and lastly
> reinsert the rows in the DataTable (otherwise the user's most recently
> selected product is the last row in the DataTable and appears at the
> bottom of the DataGrid).
>
> Is there a way to re-order the rows rather than deleting and re-inserting
> every time? Is there some way to tell the data table that the Total row
> should be the last row in the table, and the Tax row second-to-last? That
> way I could just overwrite the value in those rows rather than deleting
> and re-inserting after each time the users selects another item.
>
> Thanks in advance.
>
>



Re: Can rows be ordered in a datatable? by Cor

Cor
Sun Jul 31 02:06:09 CDT 2005

Deko,

Probably is setting the defaultview.sort of your datatable enough to do what
you want, however when you really want to sort the datatable itself.

http://www.windowsformsdatagridhelp.com/default.aspx?ID=655b418e-8e9d-4303-8be7-d6ad9bebf57f

There are more samples how to sort using for the datagrid on our website.

I hope this helps,

Cor



Re: Can rows be ordered in a datatable? by W

W
Sun Jul 31 15:32:17 CDT 2005

Deko:

I see that the others have answered your question in respect to sorting the
view. However, more than a DataView issue, this seems like a UI Issue. As
such, you could easily subclass the grid and draw a 'footer' (or if you're
using ASP.NET the grid already has them). The DataTable has a compute
method http://www.knowdotnet.com/articles/expressions.html which will
aggregate values for you (which is easy enough to do without compute but
compute is certainly cleaner). So you could then use these values and
either have two labels/textboxes etc to show them in or create your own
footer with these values. The reason I mention this is that whenever you
insert a value or change anything, compute will update those values so you
don't have to add rows, delete them or worry in any way about the physical
placement of the rows. And since this functionality is pretty common, you
can set two public properties (or howeever many) and then just pass in the
DataCOlumn name to it, and have those aggregates computed. This would give
you a ton of reusability and IMHO, this is stuff you'll likely run into
again and is a great feature for a component
"deko" <deko@nospam.com> wrote in message
news:E-mdnT5nx86rKXbfRVn-tg@comcast.com...
>I have a DataTable that is bound to a DataGrid that displays a number of
>selections from a product menu:
>
> Item1 quantity price totalAmount
> Item2 quantity price totalAmount
> TAX - - - - - - - - - - totalAmount
> TOTAL - - - - - - - - totalAmount
>
> Each time the user makes a selection, the DataTable is updated and
> re-bound to the DataGrid.
>
> The problem is I need to keep the TAX and TOTAL rows as the last rows in
> the DataTable so they appear at the bottom of the DataGrid. But the only
> way I know how to do this is to delete the rows every time the user makes
> a selection from the product menu, then recalculate the order, and lastly
> reinsert the rows in the DataTable (otherwise the user's most recently
> selected product is the last row in the DataTable and appears at the
> bottom of the DataGrid).
>
> Is there a way to re-order the rows rather than deleting and re-inserting
> every time? Is there some way to tell the data table that the Total row
> should be the last row in the table, and the Tax row second-to-last? That
> way I could just overwrite the value in those rows rather than deleting
> and re-inserting after each time the users selects another item.
>
> Thanks in advance.
>
>