all groups > dotnet windows forms databinding > september 2005 >
You're in the dotnet windows forms databinding group:
Databinding on a custom property not working properly
dotnet windows forms databinding:
I have a form with a custom property called 'KamerID'. This property is bound to a column (KAMERID) in a datatable (ABONNEES) in a dataset (dsAbo). The property is bound at runtime: this.DataBindings.Add("KamerID", dsAbo, "ABONNEES.KAMERID"); The code for the property: [Bindable(true)] public int KamerID { get { return _kamerID; } set { if (_kamerID == 0 && _aboID != 0) { _savedKamer = value; } _kamerID = value; OracleCommand kamer = new OracleCommand( "SELECT INSTELLINGEN.NAAM || ' | ' || KAMERS.KAMERNR " + "FROM INSTELLINGEN, KAMERS " + "WHERE KAMERS.INSTELLING = INSTELLINGEN.INSTELLING AND " + "KAMERID = " + _kamerID, _oradb); _oradb.Open(); linkKamer.Text = kamer.ExecuteScalar().ToString(); _oradb.Close(); kamer.Dispose(); } } When the dataset is filled, the KamerID property is triggered and the text of the LinkLabel changes. This works fine. However, if the user changes the KamerID property, the change is not reflected in the dataset. In my Save method for the form, I have this code to make sure all current edits are being saved to the dataset: this.GetNextControl(this, true).Focus(); BindingContext[dsAbo.ABONNEES].EndCurrentEdit(); This works fine to correctly update all other databindings (e.g. the Text property of textboxes), but not for the KamerID property. How can I fix this for the KamerID property?
Hi, [quoted text, click to view] <anony@nospam.com> wrote in message news:etAh51OxFHA.1256@TK2MSFTNGP09.phx.gbl... > I have a form with a custom property called 'KamerID'. This property is > bound to a column (KAMERID) in a datatable (ABONNEES) in a dataset > (dsAbo). > > The property is bound at runtime: > > this.DataBindings.Add("KamerID", dsAbo, "ABONNEES.KAMERID"); > > > The code for the property: > > [Bindable(true)] > public int KamerID > { > get > { > return _kamerID; > } > > set > { > if (_kamerID == 0 && _aboID != 0) > { > _savedKamer = value; > } > > _kamerID = value; > > OracleCommand kamer = new OracleCommand( > "SELECT INSTELLINGEN.NAAM || ' | ' || > KAMERS.KAMERNR " + > "FROM INSTELLINGEN, KAMERS " + > "WHERE KAMERS.INSTELLING = INSTELLINGEN.INSTELLING > AND " + > "KAMERID = " + _kamerID, _oradb); > > _oradb.Open(); > linkKamer.Text = kamer.ExecuteScalar().ToString(); > _oradb.Close(); > > kamer.Dispose(); > } > } > > When the dataset is filled, the KamerID property is triggered and the text > of the LinkLabel changes. This works fine. > However, if the user changes the KamerID property, the change is not > reflected in the dataset. > > In my Save method for the form, I have this code to make sure all current > edits are being saved to the dataset: > > this.GetNextControl(this, true).Focus(); > BindingContext[dsAbo.ABONNEES].EndCurrentEdit();
You have to use the exact same DataSource and DataMember (excluding fieldname) that you used for the binding, so in your case that would be : BindingContext[ dsAbo, "ABONNEES" ].EndCurrentEdit(); That's not the same as what you're doing. HTH, greetings [quoted text, click to view] > > This works fine to correctly update all other databindings (e.g. the Text > property of textboxes), but not for the KamerID property. > How can I fix this for the KamerID property? > >
Thanks for your reply! You're absolutely right, the databinding is triggered now when I try to save. However, when BindingContext[dsAbo, "ABONNEES"].EndCurrentEdit(); is invoked in the Save method, the KamerID property of the form is also triggered and the dataset pushes the old saved value to the property again. Do I have to add some code to the KamerID to push te new value to the dataset? Thank you in advance, Ruben "Bart Mermuys" <bmermuys.nospam@hotmail.com> schreef in bericht news:O$T2oMQxFHA.3812@TK2MSFTNGP09.phx.gbl... [quoted text, click to view] > Hi, > > <anony@nospam.com> wrote in message > news:etAh51OxFHA.1256@TK2MSFTNGP09.phx.gbl... > > I have a form with a custom property called 'KamerID'. This property is > > bound to a column (KAMERID) in a datatable (ABONNEES) in a dataset > > (dsAbo). > > > > The property is bound at runtime: > > > > this.DataBindings.Add("KamerID", dsAbo, "ABONNEES.KAMERID"); > > > > > > The code for the property: > > > > [Bindable(true)] > > public int KamerID > > { > > get > > { > > return _kamerID; > > } > > > > set > > { > > if (_kamerID == 0 && _aboID != 0) > > { > > _savedKamer = value; > > } > > > > _kamerID = value; > > > > OracleCommand kamer = new OracleCommand( > > "SELECT INSTELLINGEN.NAAM || ' | ' || > > KAMERS.KAMERNR " + > > "FROM INSTELLINGEN, KAMERS " + > > "WHERE KAMERS.INSTELLING = INSTELLINGEN.INSTELLING > > AND " + > > "KAMERID = " + _kamerID, _oradb); > > > > _oradb.Open(); > > linkKamer.Text = kamer.ExecuteScalar().ToString(); > > _oradb.Close(); > > > > kamer.Dispose(); > > } > > } > > > > When the dataset is filled, the KamerID property is triggered and the text > > of the LinkLabel changes. This works fine. > > However, if the user changes the KamerID property, the change is not > > reflected in the dataset. > > > > In my Save method for the form, I have this code to make sure all current > > edits are being saved to the dataset: > > > > this.GetNextControl(this, true).Focus(); > > BindingContext[dsAbo.ABONNEES].EndCurrentEdit(); > > You have to use the exact same DataSource and DataMember (excluding > fieldname) that you used for the binding, so in your case that would be : > > BindingContext[ dsAbo, "ABONNEES" ].EndCurrentEdit(); > > That's not the same as what you're doing. > > HTH, > greetings > > > > > > > This works fine to correctly update all other databindings (e.g. the Text > > property of textboxes), but not for the KamerID property. > > How can I fix this for the KamerID property? > > > > > >
I tried another approach by subclassing the linklabel and add the property 'KamerID' to this new class. After adding an event handler KamerIDChanged to this property, everything seems to work fine. <anony@nospam.com> schreef in bericht news:uy0EkoZxFHA.3712@TK2MSFTNGP10.phx.gbl... [quoted text, click to view] > Thanks for your reply! > You're absolutely right, the databinding is triggered now when I try to > save. However, when > BindingContext[dsAbo, "ABONNEES"].EndCurrentEdit(); > > is invoked in the Save method, the KamerID property of the form is also > triggered and the dataset pushes the old saved value to the property again. > Do I have to add some code to the KamerID to push te new value to the > dataset? > > Thank you in advance, > > Ruben > > "Bart Mermuys" <bmermuys.nospam@hotmail.com> schreef in bericht > news:O$T2oMQxFHA.3812@TK2MSFTNGP09.phx.gbl... > > Hi, > > > > <anony@nospam.com> wrote in message > > news:etAh51OxFHA.1256@TK2MSFTNGP09.phx.gbl... > > > I have a form with a custom property called 'KamerID'. This property is > > > bound to a column (KAMERID) in a datatable (ABONNEES) in a dataset > > > (dsAbo). > > > > > > The property is bound at runtime: > > > > > > this.DataBindings.Add("KamerID", dsAbo, "ABONNEES.KAMERID"); > > > > > > > > > The code for the property: > > > > > > [Bindable(true)] > > > public int KamerID > > > { > > > get > > > { > > > return _kamerID; > > > } > > > > > > set > > > { > > > if (_kamerID == 0 && _aboID != 0) > > > { > > > _savedKamer = value; > > > } > > > > > > _kamerID = value; > > > > > > OracleCommand kamer = new OracleCommand( > > > "SELECT INSTELLINGEN.NAAM || ' | ' || > > > KAMERS.KAMERNR " + > > > "FROM INSTELLINGEN, KAMERS " + > > > "WHERE KAMERS.INSTELLING = > INSTELLINGEN.INSTELLING > > > AND " + > > > "KAMERID = " + _kamerID, _oradb); > > > > > > _oradb.Open(); > > > linkKamer.Text = kamer.ExecuteScalar().ToString(); > > > _oradb.Close(); > > > > > > kamer.Dispose(); > > > } > > > } > > > > > > When the dataset is filled, the KamerID property is triggered and the > text > > > of the LinkLabel changes. This works fine. > > > However, if the user changes the KamerID property, the change is not > > > reflected in the dataset. > > > > > > In my Save method for the form, I have this code to make sure all > current > > > edits are being saved to the dataset: > > > > > > this.GetNextControl(this, true).Focus(); > > > BindingContext[dsAbo.ABONNEES].EndCurrentEdit(); > > > > You have to use the exact same DataSource and DataMember (excluding > > fieldname) that you used for the binding, so in your case that would be : > > > > BindingContext[ dsAbo, "ABONNEES" ].EndCurrentEdit(); > > > > That's not the same as what you're doing. > > > > HTH, > > greetings > > > > > > > > > > > > This works fine to correctly update all other databindings (e.g. the > Text > > > property of textboxes), but not for the KamerID property. > > > How can I fix this for the KamerID property? > > > > > > > > > > > >
Hi, [quoted text, click to view] <anony@nospam.com> wrote in message news:eflgl$bxFHA.464@TK2MSFTNGP15.phx.gbl... >I tried another approach by subclassing the linklabel and add the property > 'KamerID' to this new class. > After adding an event handler KamerIDChanged to this property, everything > seems to work fine.
No idea why it works better when the property is on a seperate control. A basic setup seems to work for me when binding a property on a Form. Two things can cause the value from the property to be written to the DataSource, that's BindingContext[...].EndCurrentEdit or when the control that has the property fires a validating event. It's not required to have a KamerIDChanged event, but if you do have one you must fire it when the property is changed, otherwise values will never be persisted. Greetings [quoted text, click to view] > > <anony@nospam.com> schreef in bericht > news:uy0EkoZxFHA.3712@TK2MSFTNGP10.phx.gbl... >> Thanks for your reply! >> You're absolutely right, the databinding is triggered now when I try to >> save. However, when >> BindingContext[dsAbo, "ABONNEES"].EndCurrentEdit(); >> >> is invoked in the Save method, the KamerID property of the form is also >> triggered and the dataset pushes the old saved value to the property > again. >> Do I have to add some code to the KamerID to push te new value to the >> dataset? >> >> Thank you in advance, >> >> Ruben >> >> "Bart Mermuys" <bmermuys.nospam@hotmail.com> schreef in bericht >> news:O$T2oMQxFHA.3812@TK2MSFTNGP09.phx.gbl... >> > Hi, >> > >> > <anony@nospam.com> wrote in message >> > news:etAh51OxFHA.1256@TK2MSFTNGP09.phx.gbl... >> > > I have a form with a custom property called 'KamerID'. This property > is >> > > bound to a column (KAMERID) in a datatable (ABONNEES) in a dataset >> > > (dsAbo). >> > > >> > > The property is bound at runtime: >> > > >> > > this.DataBindings.Add("KamerID", dsAbo, "ABONNEES.KAMERID"); >> > > >> > > >> > > The code for the property: >> > > >> > > [Bindable(true)] >> > > public int KamerID >> > > { >> > > get >> > > { >> > > return _kamerID; >> > > } >> > > >> > > set >> > > { >> > > if (_kamerID == 0 && _aboID != 0) >> > > { >> > > _savedKamer = value; >> > > } >> > > >> > > _kamerID = value; >> > > >> > > OracleCommand kamer = new OracleCommand( >> > > "SELECT INSTELLINGEN.NAAM || ' | ' || >> > > KAMERS.KAMERNR " + >> > > "FROM INSTELLINGEN, KAMERS " + >> > > "WHERE KAMERS.INSTELLING = >> INSTELLINGEN.INSTELLING >> > > AND " + >> > > "KAMERID = " + _kamerID, _oradb); >> > > >> > > _oradb.Open(); >> > > linkKamer.Text = kamer.ExecuteScalar().ToString(); >> > > _oradb.Close(); >> > > >> > > kamer.Dispose(); >> > > } >> > > } >> > > >> > > When the dataset is filled, the KamerID property is triggered and the >> text >> > > of the LinkLabel changes. This works fine. >> > > However, if the user changes the KamerID property, the change is not >> > > reflected in the dataset. >> > > >> > > In my Save method for the form, I have this code to make sure all >> current >> > > edits are being saved to the dataset: >> > > >> > > this.GetNextControl(this, true).Focus(); >> > > BindingContext[dsAbo.ABONNEES].EndCurrentEdit(); >> > >> > You have to use the exact same DataSource and DataMember (excluding >> > fieldname) that you used for the binding, so in your case that would be > : >> > >> > BindingContext[ dsAbo, "ABONNEES" ].EndCurrentEdit(); >> > >> > That's not the same as what you're doing. >> > >> > HTH, >> > greetings >> > >> > >> > >> > > >> > > This works fine to correctly update all other databindings (e.g. the >> Text >> > > property of textboxes), but not for the KamerID property. >> > > How can I fix this for the KamerID property? >> > > >> > > >> > >> > >> >> > >
Don't see what you're looking for? Try a search.
|
|
|