|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
textBox databinding.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 :) Use instead of Add, Remove (or clear it what mostly is the most simple)
Show quoteHide quote "Mr. X." <nospam@nospam_please.com> wrote in message news:uR8EmRN1KHA.5212@TK2MSFTNGP05.phx.gbl... > 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[MVP]" <Notmyfirstn***@planet.nl> wrote in message I don't understand.news:OhQCfVO1KHA.4412@TK2MSFTNGP02.phx.gbl... > Use instead of Add, Remove (or clear it what mostly is the most simple) 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)) Show quoteHide quote "Mr. X." <nospam@nospam_please.com> wrote in message news:u3WkElP1KHA.5972@TK2MSFTNGP06.phx.gbl... > "Cor Ligthert[MVP]" <Notmyfirstn***@planet.nl> wrote in message > news:OhQCfVO1KHA.4412@TK2MSFTNGP02.phx.gbl... >> 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 :) Just call reject changes on the dataset , datatable or datarow ( what is
apropriate in your situation ) http://msdn.microsoft.com/en-us/library/afybt7wb.aspx the datasource will through the bindingsource reflect the old values to the screen HTH Michel Posseth Show quoteHide quote "Mr. X." <nospam@nospam_please.com> schreef in bericht news:uR8EmRN1KHA.5212@TK2MSFTNGP05.phx.gbl... > 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 :) 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). Now unexpectedly bsMain.current.Row.RowState = modified - Why ???But ... 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. Show quoteHide quote "Mr. X." <nospam@nospam_please.com> wrote in message news:eCFMW9b1KHA.6104@TK2MSFTNGP06.phx.gbl... > 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 :) Hello Mr.X.
After thorough reading of your provided details my answer still stands call reject changes on the datasource the datsource is the dataset , datatable or datarow in your described situation the datarow reject changes should be called the why ? part http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/868d17f9-fad2-4e96-aab0-02c953ef87d0 :-) regardsMichel Posseth Show quoteHide quote "Mr. X." <nospam@nospam_please.com> schreef in bericht news:eCFMW9b1KHA.6104@TK2MSFTNGP06.phx.gbl... >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 :) 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 :)
Sorry for reposting - can not figure out...
Reading filenames into listbox Object disposal guidance needed Trouble With Timer Red TransparencyKey Not Working on Non Development Computer Add timer.tick event handler. Create a template. Creating array for three items forms control in a class From designer does not display |
|||||||||||||||||||||||