textBox databinding.

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 :)
 
C

Cor Ligthert[MVP]

Use instead of Add, Remove (or clear it what mostly is the most simple)
 
M

Mr. X.

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 :)
 
C

Cor Ligthert[MVP]

Textbox1.DataBindings.Clear
Textbox1.DataBindings.RemoveAt(0)
Textbox1.DataBindings.Remove(Textbox.Datatindings(0))
 
M

Mr. X.

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 :)
 
C

Cor Ligthert[MVP]

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.
 
M

Mr. X.

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 :)
 

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