Link to home
Start Free TrialLog in
Avatar of David Svedarsky
David SvedarskyFlag for United States of America

asked on

Mark up bound datagridview column 20%

Software: vb.net and sql server 2005

I need sample code to mark up a bound datagridview column 20% with a buttonclick event.


Thanks!
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Hi Dave;

That all depends if the database value can have a null as its value.
'' You can use something like this to markup all values in a single column
'' Where the value can have a database NULL in it and the data type of the db is set to money.
For i As Integer = 0 To DataGridView1.RowCount - 1
    Dim value As Decimal = IIf(IsDBNull(DataGridView1.Rows(i).Cells("Freight").Value), 0, DataGridView1.Rows(i).Cells("Freight").Value * 1.2)
    DataGridView1.Rows(i).Cells("Freight").Value = value
Next

'' Or you can use this if the column can't be a database NULL
For i As Integer = 0 To DataGridView1.RowCount - 1
    DataGridView1.Rows(i).Cells("Freight").Value *= 1.2
Next

Open in new window

Avatar of David Svedarsky

ASKER

The value can have a database NULL in it and the data type of the db is set to money.
The column is visible.

I tried everything I can think of and keep getting this error:
System.ArgumentException was unhandled
  Message="Column named FixtureUpgradePrice cannot be found.
Parameter name: columnName"
  ParamName="columnName"
  Source="System.Windows.Forms"

Any ideas?
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks!
Not a problem Dave, glad to help.