Solved

Mark up bound datagridview column 20%

Posted on 2014-07-23
5
240 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

752 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