Binding on non-default property sets datarowstate modified

J

Johan Jooris

Hi,

I've got the following problem with databinding:

If I bind a column of a dataset e.g. on the Text property of a Textbox,
everything acts as expected, i.e. if you don't make any changes to the text
in the textbox, the rowstate of the bound row stays unchanged.
On the contrary, when you bind e.g. the Tag property of the Textbox, instead
of the text property, the rowstate turns to modified when leaving the
textbox (or by calling the bindingmanager.endcurrentedit method), even if
you haven't changed a thing.
This is very inconveniant because it causes unnecessary updates of the
database.
It seems that binding on the non default property (Text) causes changes of
the underlying dataset.
You can find the test cde below (button1_click fills a datasource where the
control is bound to; acceptchanges ensures that the rowstate is modified)
The button2_click writes out the rowstate before and after the
endcureentedit call of the bindingmanager.

How can we avoid this ???

Thanks !!!

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

_bm = Me.BindingContext(Me._data, "TEST")

Me._data.Clear()

Me._data.TEST.AddTESTRow("ID", "TEKST")

Me._data.AcceptChanges()

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

Debug.WriteLine(Me._data.TEST(0).RowState.ToString)

Me._bm.EndCurrentEdit()

Debug.WriteLine(Me._data.TEST(0).RowState.ToString)

End Sub
 
A

Andrew Smith \(Infragistics\)

Basically the bindingmanager has no way of knowing when the property has
changed so it must assume that it is dirty. You would have to derive from
textbox, define an event of type eventhandler named TagChanged and raise
that when the tag property is changed. You'll probably need to shadow the
tag property (or define a new property to which you'll bind) so you know
when to raise the event.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top