2016-08-04 8 views
1

私は非常に奇妙に見えるこの問題を抱えています.Windows 8のコンピュータでエラーメッセージのみを送信するプログラムを開発しますが、Windows 7とWindows 10は完全に機能します。VB.NETエラーDatagridViewCellValueChanged Windows 8

私はいくつかのコード行で、具体的にはイベントでDataGridViewCellValueChanged私は数字をコイン形式に変換しますが、変な事柄は(私の意見では)セルの値と私は、cellvaluechangedイベントは、ユーザーがセル内に何かを入力したときに実行されるべきだと思っています。そのセルから、CellEndEditと似ていますが、セルの値が変更されたときだけです。ユーザは、セルのフォーカスを失うことなく指定された列内の任意のセルの任意の文字を押し、エラーを送信する。 Windows 7のプログラムで自分のコンピュータで

これはコードです

あまりにもよく、およびWindows 10上で動作します。私は、エラーメッセージの画像が必要とされていないことを知っている

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 

が、望んでいましたユーザーがDataGridViewに入力したデータを表示します。

enter image description here

メッセージは言う:

文字列から変換 "$ 8.00" '進' にサポートされていません。

あなたがコード内で見ることができるように、私はこれだけ一時的にエラーを修正するが、それが唯一のWindows 8

答えて

0

にこのコードかもしれないがなぜ起こるか理解していない、メッセージの表示を停止するエラーを処理しなければなりませんでしたデバッグに役立ちます。あなたは、割り当てに入るまでにsを "$ 8.00"にしたいので、問題はありません。エラーメッセージに予想外の値が表示されていても、割り当て後のある時点でグリッドに表示されている場合は、タイミングに問題があることがわかります。

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 

フォーマット方法はおそらく動作しますが、通貨フォーマットを使用しないのはなぜですか? CurrentCultureが機能しない場合は、それを指定できます。

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 

通貨のフォーマットについてを参照してください:https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.110).aspx#CFormatString

+0

だけで、でも私は最初、私はそれをよりよく理解したいので、あなたのコードを試してみてください、しかし、あなたが私を言及したことは私の問題を解決するためのアイデアを与えていない、あなたに感謝これらのコンピュータの設定を変更する必要がありました。 – Rchrd