Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27212

VS 2010 problem in digit grouping at textchanged event

$
0
0
hi
i am making a custom textbox with realtime digit grouping property
my problem is the "." in decimal numbers that formatnumber or other functions don't format number correctly

Code:

Private Sub SHTextBox_TextChanged(sender As Object, e As EventArgs) Handles Me.TextChanged
        Select Case mInputType
            Case Inputs.Numbers
                If mAllowNegativeNumber = True Then  ' this is property
                    If HasNegative(Me.Text.Trim) Then  ' detect negative operator
                        If CheckNegative(Me.Text.Trim) = True Then ' check if Negative operator is first character
                            If mSeparator = True And Me.TextLength > 1 Then
                                Me.Text = FormatNumber(-Me.Text.Trim.Replace("-", ""), 0, , , TriState.True)
                                Me.SelectionStart = Me.TextLength
                            End If
                        Else
                            MessageBox.Show("Validation", "Negative Operator Must be First Character", MessageBoxButtons.OK, MessageBoxIcon.Information)
                            Me.Clear()
                            Me.Focus()
                        End If
                    Else
                        If mSeparator = True And Me.TextLength > 0 Then
                            Me.Text = FormatNumber(Me.Text.Trim, 0, , , TriState.True)
                            Me.SelectionStart = Me.TextLength
                        End If
                    End If
                Else
                    If mSeparator = True And Me.TextLength > 0 Then
                        Me.Text = FormatNumber(Me.Text.Trim, 0, , , TriState.True)
                        Me.SelectionStart = Me.TextLength
                    End If
                End If



            Case Inputs.Decimals

                If mAllowNegativeNumber = True Then
                    If HasNegative(Me.Text.Trim) Then
                        If CheckNegative(Me.Text.Trim) = True Then
                            If mSeparator = True And Me.TextLength > 1 Then
                                Dim val As Decimal = Convert.ToDecimal(Me.Text.Trim)
                                Me.Text = val.ToString("#,##0.#######")
                                Me.SelectionStart = Me.TextLength
                            End If
                        Else
                            MessageBox.Show",("Validation", "Negative Operator Must be First Character", MessageBoxButtons.OK, MessageBoxIcon.Information)
                            Me.Clear()
                            Me.Focus()
                        End If
                    Else
                        If mSeparator = True And Me.TextLength > 0 Then
                            Dim val As Decimal = Convert.ToDecimal(Me.Text.Trim)
                            Me.Text = val.ToString("#,##0.#######")
                            Me.SelectionStart = Me.TextLength
                        End If
                    End If
                Else
                    If mSeparator = True And Me.TextLength > 0 Then
                        Dim val As Decimal = Convert.ToDecimal(Me.Text.Trim)
                        Me.Text = val.ToString("#,##0.#######")
                        Me.SelectionStart = Me.TextLength
                    End If
                End If



             
        End Select
    End Sub

my main problem is in Decimal part, firts i use formatnumber function for decimal but dont work then i use "#,##0.##" but dont work too

please help me

Viewing all articles
Browse latest Browse all 27212


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>