Solved

Mark up bound datagridview column 20%

Posted on 2014-07-23
5
230 Views
Last Modified: 2014-08-01
Software: vb.net and sql server 2005

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


Thanks!
0
Comment
Question by:dave_sky
  • 3
  • 2
5 Comments
 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility
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

0
 

Author Comment

by:dave_sky
Comment Utility
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?
0
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
Comment Utility
Hi Dave;

According to the error message the column FixtureUpgradePrice cannot be found and is most likely due to a spelling error or capitalization does not match that which is set for the column.

So this is the code you should be using because database NULL can be in the column. You need to verify the column name being used in the statement.
For i As Integer = 0 To DataGridView1.RowCount - 1
    Dim value As Decimal = IIf(IsDBNull(DataGridView1.Rows(i).Cells("FixtureUpgradePrice").Value), 0, DataGridView1.Rows(i).Cells("FixtureUpgradePrice").Value * 1.2)
    DataGridView1.Rows(i).Cells("FixtureUpgradePrice").Value = value
Next

Open in new window

0
 

Author Closing Comment

by:dave_sky
Comment Utility
Thanks!
0
 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility
Not a problem Dave, glad to help.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now