www.nicholasdavis.info
A client of mine had made a request to take the total of a column from the MS DataGrid and in turn, spit it out into a TextBox. Alright... So my first reaction was to loop through each individual record in the grid. It would have worked, but it would not have been pretty, nor speedy by any means. Then I got to wondering if the DataGrid itself had means of calculating the total of a column. I did some quick research on the subject and alas, I could not find a total for the DataGrid. From there I got to thinking, "Well, if the grid is really just an interpretation of it's DataSource, maybe I should be looking at the DataTable?"
Bingo.
textBox1.Text = "$" + dtPurchases.Compute("SUM(Amount)", string.Empty).ToString();
textBox1.Text = "$" + dtPurchases.Compute("SUM(OrigEquityAmt)", "UserName = 'Billy'").ToString();
posted at 2/28/2008 1 Comments