Solved

Mark up bound datagridview column 20%

Posted on 2014-07-23
5
233 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 63

Expert Comment

by:Fernando Soto
ID: 40215407
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
ID: 40215718
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 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 40216941
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
ID: 40234667
Thanks!
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 40234885
Not a problem Dave, glad to help.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

810 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