For simple binding, the answer is no, you do not need to implement an
interface. All you need to do to bind the class below to a TextBox is
ensure that FirstName, LastName and Dedication are properties (you can't
bind to instance member variables).
For example, assuming that FirstName is a string property, to bind a text
box to it do the following:
m_TextBox.DataBindings.Add("Text", anInstanceOfAuthor, "FirstName");
You should also define a property change notification event. Fill out the
class for the FirstName example, it would look like this:
class Author
{
public string FirstName
{
get{ return m_sFirstName; }
set
{
bool bFire = m_sFirtName != value;
m_sFirstName = value;
if(bFire)
Fire_FirstNameChanged();
}
}
public event EventHandler FirstNameChanged;
private Fire_FirstNameChanged()
{
if(FirstNameChanged != null)
FirstNameChanged(this, EventArgs.Empty);
}
}
For complex binding (like the data grid), yes you need to implement one or
more interfaces. I haven't done it, so I can't help you. Look at
IBindingList...
Now would be a great time for Mark Boulter to post his complex data binding
sample that he mentioned some time ago! ;-)
HTH,
Seang
-----Original Message-----
From: Curtis Koppang [mailto:[EMAIL PROTECTED]]
Sent: Thursday, May 30, 2002 11:31 AM
To: [EMAIL PROTECTED]
Subject: [DOTNET] What do I need to implement to support DataBinding
Say I have a simple class which represents a single data entity, like the
following:
class Author {
public FirstName;
public LastName;
public Dedication;
}
Do I need to implment any specific interfaces to support data binding? I
checked the archives and most of the information has to do with exposing
Authors (plural) or is outdated (pre-RTM).
Thanks,
curt
You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.
You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.