DataBinding custom class to textBox

S

Steve

Seems like it should be simple. I found an article on
MSDN(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/
html/frlrfsystemwindowsformsbindingclasstopic.asp) that explains doing it
with a DataSet.

I'm using a custom object with a couple of string members. I can't believe
that databinding is an incredibly complex as it appears to be. From what I
have read, it would be much simpler to manually maintain the relationships
between control and data.

I must be missing something. Given a class;

<code>
public class CMyClass
{
private string m_name;
// ctor code...


public string Name
{
get{ return m_name; }
}
}
</code>

If I wanted to bind that Name property to a text control, I would think it
would be as simple as;
CMyClass c - new CMyClass();
textBox1.DataBindings.Add( new Binding("Text", c, Name));
or even:
textBox1.DataBindings.Add( new Binding("Text", c, c.Name));


This throws exceptions that it can't find the data member. After
researching it looks like my CMyClass needs to implement IBindingList or
ITypedList
yuck, those are big interfaces.

This wasn't intended to be a complain fest, I'm just surprised, it's SOOO
much easier on WebForms. I must be missing something. Please, someone...
guide me ;)
 
B

Bart Mermuys

Hi,

Steve said:
Seems like it should be simple. I found an article on
MSDN(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/
html/frlrfsystemwindowsformsbindingclasstopic.asp) that explains doing it
with a DataSet.

I'm using a custom object with a couple of string members. I can't
believe
that databinding is an incredibly complex as it appears to be. From what
I
have read, it would be much simpler to manually maintain the relationships
between control and data.

I must be missing something. Given a class;

<code>
public class CMyClass
{
private string m_name;
// ctor code...


public string Name
{
get{ return m_name; }
}
}
</code>

If I wanted to bind that Name property to a text control, I would think it
would be as simple as;
CMyClass c - new CMyClass();
textBox1.DataBindings.Add( new Binding("Text", c, Name));
or even:
textBox1.DataBindings.Add( new Binding("Text", c, c.Name));

What about :
textBox1.DataBindings.Add( new Binding("Text", c, "Name") );

or even :
textBox1.DataBindings.Add( "Text", c, "Name" );


HTH,
Greetings
 
S

Steve

Bart Mermuys said:
Hi,



What about :
textBox1.DataBindings.Add( new Binding("Text", c, "Name") );

or even :
textBox1.DataBindings.Add( "Text", c, "Name" );


HTH,
Greetings


Wow, I feel really foolish. ;)
Thanks for the help Bart!
 

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