Note: Forums will be making significant UX changes to address key usability improvements surrounding search, discoverability and navigation. To learn more about these changes please visit the announcement which can be found HERE.
Use Text box Validation in DatagridView Using VB.NET

Locked Use Text box Validation in DatagridView Using VB.NET

  • 21 februarie 2012 06:22
     
     

     This Code for dataGridViewValidation-----

     PrivateSubGrdInvestment_EditingControlShowing(ByValsender AsSystem.Object, ByVale AsSystem.Windows.Forms.DataGridViewEditingControlShowingEventArgs) HandlesGrdInvestment.EditingControlShowing

            txtAmt = TryCast(e.Control, TextBox)

            IftxtAmt IsNotNothingThen

                IfGrdInvestment.CurrentCell.OwningColumn.Name = "Amount"Then

                    ' Remove an existing event-handler

                    RemoveHandlertxtAmt.KeyPress, AddressOfTextBox_KeyPress

                    ' Add the event handler.

                    AddHandlertxtAmt.KeyPress, AddressOfTextBox_KeyPress

                EndIf

            EndIf

        EndSub

        PrivateSubTextBox_KeyPress(ByValsender AsSystem.Object, ByVale AsSystem.Windows.Forms.KeyPressEventArgs)

            IfGrdInvestment.CurrentCell.OwningColumn.Name = "Amount"Then

                IfChar.IsDigit(e.KeyChar) Ore.KeyChar = "."cOre.KeyChar = "€cThen

                    e.Handled = False

                Else

                    e.Handled = True

                    e.KeyChar = "\0"

                EndIf

            EndIf

        EndSub

        PrivateSubGrdInvestment_CellValidating(ByValsender AsSystem.Object, ByVale AsSystem.Windows.Forms.DataGridViewCellValidatingEventArgs) HandlesGrdInvestment.CellValidating

            IfGrdInvestment.CurrentCell.OwningColumn.Name = "Amount"Then

                IfNotIsNumeric(txtAmt.Text) Then

                    MsgBox("Amount must be a number", MsgBoxStyle.Information)

                    txtAmt.Text = "0.00"

                EndIf

            EndIf

        EndSub

Toate mesajele

  • 21 februarie 2012 17:36
     
     

    Hi Mukesh,

    As you appear to have a VB.Net question, and not a Transaction Programming question (this forum's topic), please ask in the VB.Net developer forums for best answers:

    Visual Basic Forum

    Regards

    Olivia