DataGridView как отловить неправильный ввод?

pshik
Дата: 15.01.2010 21:50:23
Сделал Databining к объекту с Property = Double
Если ввожу текст, то сразу краш.

Как отловить и не позволить вводить текст вместо чисел.

Спасибо
pshik
Дата: 18.01.2010 18:26:29
ВОт нашёл сам:

 Private Sub DataGridView2_CellValidating(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles DataGridView2.CellValidating

       
        Dim number As [Double]
        Dim style As Globalization.NumberStyles
        Try

            style = Globalization.NumberStyles.Number 'Or Globalization.NumberStyles.AllowCurrencySymbol Or Globalization.NumberStyles.AllowThousands

          
            If [Double].TryParse(e.FormattedValue.ToString(), style, Globalization.CultureInfo.CurrentCulture, number) = False Then
                ' error: the input does not parse to double
                e.Cancel = True
                MsgBox("You can enter only numeric value.")
       
                'Else

            End If
   

            If e.Cancel Then
                ' go back to the old value
                Me.DataGridView2.RefreshEdit()

            End If

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub