Solved

Mark up bound datagridview column 20%

Posted on 2014-07-23
5
232 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
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 62

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 62

Expert Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 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

19 Experts available now in Live!

Get 1:1 Help Now