textBox databinding.

  • Thread starter Thread starter Mr. X.
  • Start date Start date
M

Mr. X.

Hello.
I have connected textbox by databinding to a BindingSource object (to a
specific column of a specific table).

Everything is fine ...
But what if I want to undo the change I have made by the textbox.
(It may be a textbox or any other binded control).
How can I do that ?

Thanks :)
 
Cor Ligthert said:
Use instead of Add, Remove (or clear it what mostly is the most simple)

I don't understand.
What this is related to undo my changes (of only field of the table).

Thanks :)
 
Textbox1.DataBindings.Clear
Textbox1.DataBindings.RemoveAt(0)
Textbox1.DataBindings.Remove(Textbox.Datatindings(0))
 
I want to clear not the whole binding, but partial.

The situation is :
I have a main screen, which has a dataGridView, which connected to
datasource by BindingSource object.
Also a sub screen called by the main screen, which has textBox object on it,
which also connected to the same bindSource object.

For simplicaty :
main screen = frmMain
data grid view - dgMain
BindingSource - bsMain (a local variable in each form - main and subform,
that has the same value for both).
sub screen = frmSubScreen
text box (on the sub-screen) - txtSubTestValue

On dgMain there are two rows (also two rows in the table of database).
First time I am on the first row of dgMain.
When clicking to show the frmSubScreen - subScreen has the current row
selected.
Now I am changing the txtSubTestValue, which is connected to a field.
.... Now I want to do cancel : I did bsMain.cancelEdit, but I know this
wrong - why ???
I am closing frmSubScreen, and return to frmMain.
If I check now the bsMain.current.Row.RowState = unchanged.
Now I am choosing the second row of dgMain,
and go again to the first row of dgMain (which I have changed, but did
:bsMain.cancelEdit).
But ...
Now unexpectedly bsMain.current.Row.RowState = modified - Why ???

And what is the best approach solving this problem ?

(For other situation, whether the original state is modified - It was
solved, by a function I have made. I only need to set the original value of
each column, which I keep it on an array, which holds all the related object
on screen, that has databinding on it).

Thanks :)
 
Do you really think that we are magicians, you are behind your screen with
the full code before you, using a database which we not have.

This means the same like we do in this kind of situations, much tears and
sometimes sweat.

Luckily no blood.
 
O.K.
Good link - Thank you very much.

Problem solved.
I think I understand now.
I don’t need any special routine.
For the main screen and sub screen - I created a new BindSource (not the
same one, not point to the same memory,
but both are linked to the same datasource).
For the sub screen I did cancelEdit.
Because it acts as layers - at the most top screen I should do a
AcceptChanges or RejectChanges for the whole row
(That will change only in memory ... or dataadapter.update if I realy want
to update in database).

I see - when I first changing any of the linked object to datasource - the
is "auto-BeginEdit", so I don't need to worry about it.

Thanks :)
 
Back
Top