Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TextBox issue when binded to datatable

Status
Not open for further replies.

vbtest5

IS-IT--Management
Nov 16, 2002
37
0
0
IN
Hi,

We have an entry form that is binded to the datatable. There is an amount field. On this amount text box, when we delete the previous value and press tab key to go to next text box, the old value is displayed again in the text box? Why does this happen?

Regards,
Varsha
 
This is the binding manager doing a bit of exception handling for you. The column you are binding the textbox to needs a numeric value, but you are passing it an empty string when you tab out of it. You can make the value equal zero when an empty string is entered by using the Parse event:
Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim dt As New DataTable

        dt.Columns.Add(New DataColumn("Int", GetType(Int32)))

        For i As Int32 = 1 To 10

            Dim dr As DataRow = dt.NewRow()

            dr(0) = i

            dt.Rows.Add(dr)

        Next

        Dim b As Binding = New Binding("Text", dt, "Int")

        AddHandler b.Parse, AddressOf TextBox1_Parse

        TextBox1.DataBindings.Add(b)

End Sub

Private Sub TextBox1_Parse(ByVal sender As Object, ByVal e As ConvertEventArgs)

        If e.Value.ToString = "" Then e.Value = 0

End Sub
 
hi SHelton,

Thanks for your reply. I also find that even if I type 1 or 2 numeric key values and press the tab key, I again get back the same old value. Why?

Regards,
Varsha
 
Are you sure the data column is not set to ReadOnly ? Otherwise, I cannot see why the value is changing back - I cannot reproduce your problem using the code above.
 
Hi there,

Your solution worked.... Thanks a lot! It helped a lot since my project was under implementation phase.

Regards,
Varsha
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top