locked
Use Text box Validation in DatagridView Using VB.NET

    Question

  •  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

    Tuesday, February 21, 2012 6:22 AM

All replies

  • 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

    Tuesday, February 21, 2012 5:36 PM