Processing
 

VB.NET error DatagridViewCellValueChanged Windows 8

04/08/2016 17:16#1

Rchrd

Member

Joined at: 6 months ago

Post: 1

Thank: 0

Thanked: 0

I have this problem that looks very strange, I develop a program which sends only error message on computers with Windows 8, but Windows 7 and Windows 10 works perfectly.

I will discuss a little about the error, in a few lines of code, specifically in the event DataGridViewCellValueChanged I convert a number to coin format, but the strange thing is that the event runs (in my opinion) before they change the value of the cell and I think the cellvaluechanged event should be executed when the user typed something in the cell and then out of that cell, something "similar" to CellEndEdit but only when the value of the cell change, but in this specific case the user presses any character in any cell in a column specified without losing the focus of the cell and sends an error.

On my computer with windows 7 program works well and on a Windows 10 too

This is the code:

Private Sub GridCatalogo_CellValueChanged(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles GridCatalogo.CellValueChanged     If GridCatalogo.Columns(e.ColumnIndex).ToolTipText = "$" Then         If IsNothing(GridCatalogo.Item(e.ColumnIndex, e.RowIndex).Value) = False Then             Try                 GridCatalogo.Item(e.ColumnIndex, e.RowIndex).Value = Format(CType(GridCatalogo.Item(e.ColumnIndex, e.RowIndex).Value, Decimal), "$#,##0.00")             Catch ex As Exception                 'MsgBox(ex.Message)             End Try         End If     End If  End Sub 

I know that the image of an error message is not needed, but wanted to show the data that the user typed in the DataGridView.

VB.NET error DatagridViewCellValueChanged Windows 8

The message says:

The conversion from string "$8.00" to 'Decimal' is unsupported.

As you can see in the code, I had to handle the error to stop displaying the message, so only temporarily fix the error but do not understand why that happens only in Windows 8

04/08/2016 18:35Top#2

Verdolino

Member

Joined at: 11 months ago

Post: 2

Thank: 0

Thanked: 0

This code might help you to debug. You want s to be "$8.00" by the time you get to the assignment, and you should have no problem. If the error message shows a value you didn't expect, but it is in the grid at some point after the assignment, then you know you have a timing issue.

Private Sub GridCatalogo_CellValueChanged(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles GridCatalogo.CellValueChanged     If GridCatalogo.Columns(e.ColumnIndex).ToolTipText = "$" Then         If IsNothing(GridCatalogo.Item(e.ColumnIndex, e.RowIndex).Value) = False Then             Dim s As String = "not set"             Dim d As Decimal = Decimal.MinValue             Try                 s = GridCatalogo.Item(e.ColumnIndex, e.RowIndex).Value                 d = CType(s, Decimal)                 GridCatalogo.Item(e.ColumnIndex, e.RowIndex).Value = Format(d, "$#,##0.00")             Catch ex As Exception                 MsgBox(String.Format("s={0}, d={1}, ex.message={2}", s, d, ex.Message))             End Try         End If     End If End Sub 

Your format method probably works, but why not use a currency format? If CurrentCulture doesn't work, you can specify it.

Sub Main()     Dim currencyString = "$8.00"      Dim currencyOPFormat = Format(CType(currencyString, Decimal), "$#,##0.00")      Dim currencyDecimal = Decimal.Parse(currencyString, Globalization.NumberStyles.Currency)     Dim currencyNewFormat = currencyDecimal.ToString("C", CultureInfo.CurrentCulture)      Console.WriteLine("Original: " & currencyOPFormat)      Console.WriteLine("Parsed Decimal: " & currencyDecimal)     Console.WriteLine("Formatted Decimal: " & currencyNewFormat)      Console.ReadLine() End Sub 

See about currency format: https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.110).aspx#CFormatString

Similar articles

Window Registry create key not working in java

6 months ago - Reply: 1 - Views: 76

Metro App crash on Windows 10

7 months ago - Reply: 2 - Views: 116

.dll file missing after php upgrade

7 months ago - Reply: 1 - Views: 55

Notepad++ launch multiple HTML within browser

7 months ago - Reply: 0 - Views: 3

Access 2003 freezing

7 months ago - Reply: 0 - Views: 2

Icon Handler Shell Extension not called

7 months ago - Reply: 1 - Views: 24

Border color of combox does not change - Windows 8

7 months ago - Reply: 3 - Views: 140

VB.NET error DatagridViewCellValueChanged Windows 8

8 months ago - Reply: 1 - Views: 40

I made a mistake when installing Hyper-V [on hold]

8 months ago - Reply: 0 - Views: 8

vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re