2 Replies - 200 Views - Last Post: 11 February 2019 - 09:46 PM Rate Topic: -----

#1 nyt1972   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 98
  • Joined: 04-February 10

Concatenate % sign with Cell value in datagridview

Posted 09 February 2019 - 01:54 AM

Hello,

I have datagridview have two columns with values like below:

Discount     Is_Percent
  1500            0
  20.00           1
  1000            0


I want if the Cell Is_Percent is 1 then the Discount should look like 20.00%.

For that I tried the below code

 For Each row As DataGridViewRow In dgw.Rows
                If row.Cells("isPercent").Value = 1 Then
                    row.Cells("Discount").Value = row.Cells("Discount").Value.ToString() & "%"
                End If
            Next



but I get the error message

20.00% is not a valid value for decimal

pls help.

This post has been edited by nyt1972: 09 February 2019 - 11:25 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Concatenate % sign with Cell value in datagridview

#2 IronRazer   User is offline

  • Custom Control Freak
  • member icon

Reputation: 1533
  • View blog
  • Posts: 3,861
  • Joined: 01-February 13

Re: Concatenate % sign with Cell value in datagridview

Posted 09 February 2019 - 03:44 PM

It appears that this is because the % character is not a valid numeric value for a Decimal type number. A Decimal type value would only be numbers with an optional decimal point. Your ispercent column is apparently set to contain Decimal types so, it would need to be changed to a String type instead, so that it allows a % character to be displayed.

However, you might be able to use the CellFormatting event to do this without changing the column type, I am not sure. I don't use DataGridViews very much.
Was This Post Helpful? 1
  • +
  • -

#3 nyt1972   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 98
  • Joined: 04-February 10

Re: Concatenate % sign with Cell value in datagridview

Posted 11 February 2019 - 09:46 PM

Thanks IronRazor changing column's datatype solved the problem.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1