"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:uo**************@TK2MSFTNGP10.phx.gbl...
Justin,
Can you show me with this sample what you mean (I have seen the situation
that you are describing however first this simple one because you are
talking about simple databinding)
\\\This sample needs a textbox and two buttons on a form
Dim dt As New DataTable
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
dt.Columns.Add("Field")
TextBox1.DataBindings.Add("Text", dt, "Field")
dt.LoadDataRow(New Object() {"1"}, True)
dt.LoadDataRow(New Object() {"2"}, True)
End Sub
Private Sub TextBox1_Validating(ByVal sender _
As Object, ByVal e As System.ComponentModel.CancelEventArgs) _
Handles TextBox1.Validating
If TextBox1.Text.Length > 0 Then
If Not IsNumeric(TextBox1.Text) Then
MessageBox.Show("There was an error ")
TextBox1.Focus()
e.Cancel = True
End If
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
If BindingContext(dt).Position _
< dt.Rows.Count Then
BindingContext(dt).Position += 1
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
If BindingContext(dt).Position > 0 Then
BindingContext(dt).Position -= 1
End If
End Sub
///
Hi Cor
Thanks for continuing with this. Your example works exactly as I would
like, however as soon as you specify that the datatable's column should be a
number, the behaviour changes.
Add another textbox TextBox2 and change the form's load behaviour as shown
below (my actual code uses SqlClient objects but this illustrates the
point). You now find, without changing any other coding, that your invalid
text entry in the integer column disappears and magically returns to the old
value. That is, the behaviour changes when you have a typed dataset. I
understand and accept that this is default behaviour, but do you need to be
a black-belt dotnet code guru to modify it slightly?
Thanks for any continued interest.
Dim r As DataRow
Dim colString As DataColumn = New DataColumn("StringCol")
colString.DataType = System.Type.GetType("System.String")
dt.Columns.Add(colString)
Dim colInt32 As DataColumn = New DataColumn("Int32Col")
colInt32.DataType = System.Type.GetType("System.Int32")
dt.Columns.Add(colInt32)
r = dt.NewRow()
r("StringCol") = "Number Six"
r("Int32Col") = 6
dt.Rows.Add(r)
r = dt.NewRow()
r("StringCol") = "Number Eight"
r("Int32Col") = 8
dt.Rows.Add(r)
TextBox1.DataBindings.Add("Text", dt, "Int32Col")
TextBox2.DataBindings.Add("Text", dt, "StringCol")