Re: DataGrid columns math
A better option would be to add another DataColumn to your DataTable after populating it and setting its Expression property. The values will then be calculated automatically with no need for code at all.
Re: DataGrid columns math
So the unbound data column i added called value% could i use this column for the expression? And could you just give me a very basic walkthrough of a simple expression, just enough so i can figure out the rest.
edit:: ok i see where i do this in the dataset designer, so just a couple of examples of how the expression syntax works as i've never used this feature before
Re: DataGrid columns math
That's exactly what the documentation is for. Open the MSDN Library and look up DataColumn.Expression. There's your examples and more besides.
Re: DataGrid columns math
ok sir i got the expression working, one thing though in MSDN syntax i dont see a round function, any tips on rounding the expression?
Re: DataGrid columns math
The options available to you are limited. You could try the CONVERT function to see if it will convert your Double to an Int32. If it does, just check to see whether it rounds or truncates. If it truncates then you could just add 0.5 to everything before converting.
Re: DataGrid columns math
Yea it truncates, just thinking out loud here but if i set the expression to only run if the column row value is null (so as a new row is added) couldnt i pass the columns through a math.round function on that datagridview (i'm using parent/child tables using one to many) when saving so it writes back the rounded value to the sql server?...if ya get my drift
ok forget that, expression is read only
Re: DataGrid columns math
ok well here's how i kinda did it.
I re did the test table and added a second column called total2 to use as my expression and removed it from view so as the table updates it runs through.
vb Code:
Dim cr As Decimal
For count As Integer = 0 To TestDataGridView.Rows.Count - 1
Dim currentcell As DataGridViewCell = TestDataGridView.Rows(count).Cells("total2")
Dim currentcell2 As DataGridViewCell = TestDataGridView.Rows(count).Cells("total")
cr = Decimal.Round(currentcell.Value, 2)
currentcell2.Value = cr