Groups | Blog | Home
all groups > dotnet windows forms databinding > november 2005 >

dotnet windows forms databinding : Simple data binding to a textbox


Arne
11/30/2005 11:56:09 AM
Databinding works only one way
da.Fill(data, "SubClass")
SubClassDescription.DataBindings.Clear()
SubClassDescription.DataBindings.Add("text", data.Tables(0) ,
"SubClassDescription")

Putting the edits back into the data source doesn't work!
Dim manager As BindingManagerBase
manager = Me.BindingContext(data, "SubClass")
manager.EndCurrentEdit()
subclass = row.ItemArray(0)

How can I get databinding to work? All I want to do is to separate data
before and after edits so that I can determine if I need to update the
Bart Mermuys
11/30/2005 9:52:05 PM
Hi,

[quoted text, click to view]

No, you're asking for the wrong BindingManagerBase. You need to specify
exactly the same DataSource and DataMember(excluding field so it can be an
empty string and may be omitted) as the ones you used for the binding. So
in your case that would be:

Dim manager As BindingManagerBase
manager = Me.BindingContext( data.Tables(0) )
manager.EndCurrentEdit()

subclass = row.ItemArray(0)

[quoted text, click to view]

You could use :
If ( Not data.Tables(0).GetChanges() Is Nothing ) Then
' datatable has changes
End If

HTH,
Greetings


Arne
12/2/2005 5:59:02 AM
Bart,
This code works fine
SubClassDescription.DataBindings.Add("text", data.Tables(0)

This code doesn't work
If ( Not data.Tables(0).GetChanges() Is Nothing ) Then
' datatable has changes
End If
Thanks
Arne

[quoted text, click to view]
Arne
12/2/2005 5:59:02 AM
Bart,
This code works fine
SubClassDescription.DataBindings.Add("text", data.Tables(0)

This code doesn't work
If ( Not data.Tables(0).GetChanges() Is Nothing ) Then
' datatable has changes
End If
Thanks
Arne

[quoted text, click to view]
Bart Mermuys
12/2/2005 3:42:38 PM
Hi Arne,

[quoted text, click to view]

Did you first call EndCurrentEdit ? Like :

'
' bind
'
SubClassDescription.DataBindings.Add( "Text", data.Tables(0), "SomeField" )

'
' check for changes (notice the same DataSource used for
' BindingContext as the one that was used for the binding.)
'
BindingContext( data.Tables(0) ).EndCurrentEdit()

If ( Not data.Tables(0).GetChanges() Is Nothing ) Then
' datatable has changes
MessageBox.Show("DT has changes")
End If

[quoted text, click to view]

If this doesn't help you'll need to provide more information , like all
relevant code that reproduces the problem.

HTH,
Greetings


[quoted text, click to view]

AddThis Social Bookmark Button