By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,361 Members | 2,168 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,361 IT Pros & Developers. It's quick & easy.

DataBinding to Custom Class breaks after New instance: how to get around this?

P: n/a
Hi,

I'm having the following situation:

- A class clsFournisseur with public property's which raise a
MyPropertyChanged-event in the Set-method for each Property.
Public Event NomChanged As EventHandler
Public Property Nom() As String
Get
Return m_strNom
End Get
Set(ByVal Value As String)
m_strNom = Value
RaiseEvent NomChanged(Me, New EventArgs())
End Set
End Property
- A Form, with an instance of my clsFournisseur: "Private WithEvents
MyEntreprise As New clsFournisseur".
- Proprty's of this Myentreprise are bound to controls on the Form:
"Me.txtNom.DataBindings.Add("Text", MyEntreprise, "Nom")"

When I change the value in my txtNom.Text, the MyEntreprise.Nom-property is
changed. When I change the MyEntreprise.Nom, my txtNom.Text is changed.

So far so good. BUT:
When in my Form I want to use another clsFournisseur, there isn't anymore
databinding. I do this like this:
- MyEntreprise = New clsFournisseur(intEntrepriseID)
or
- MyEntreprise = New clsFournisseur()

I guess this is normal behaviour because, even when it still has the same
name, it isn't the same class anymore. But I still want to have this
databinding! And a weird thing: the txtNom.Databindings.Count = 1, so the
TextBox thinks there is still the databinding...

Does anybody know how I should do this? Am I doing anything wrong? Should I
Clear all the DataBindings after echt new instance of a class and put them
back?

Any help would be really appreciated.

Thanks a lot in advance,

Pieter
PS: I'm using the CTP from august of Visual Studio .NET 2005


Sep 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Pieter,

You are using forever for an "object" the name "class".

You bind to an object. If you have renewed that, than the binding is gone.

See it as this
dim a as object 'normally you use its type name by instance ThisClass
a = new ThisClass
a = new ThisClass

Now there are in fact two objects the first a and the second a. The first
one will be released by the GC as soon as that starts doing its job because
it has not any reference anymore.

I thought that this was the base of your question.

I hope this helps,

Cor
Sep 20 '05 #2

P: n/a
Thansk Cor, it's indeed the confirmation of what I thougt.
But isn't there any solution for the DataBinding? Is the only solution I
have to Clear all the DataBindings and than reset them back afterwarths?

Thansk anyways,

Pieter
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:u3**************@TK2MSFTNGP12.phx.gbl...
Pieter,

You are using forever for an "object" the name "class".

You bind to an object. If you have renewed that, than the binding is gone.

See it as this
dim a as object 'normally you use its type name by instance ThisClass
a = new ThisClass
a = new ThisClass

Now there are in fact two objects the first a and the second a. The first
one will be released by the GC as soon as that starts doing its job because it has not any reference anymore.

I thought that this was the base of your question.

I hope this helps,

Cor

Sep 20 '05 #3

P: n/a
Pieter,

Your question is complete on MSDN

Databindings.clear

http://msdn.microsoft.com/library/de...cleartopic.asp

I hope this helps,

Cor
Sep 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.