For Programmers: Free Programming Magazines  


Home > Archive > C# > June 2006 > Binding to Business Objects and Generic List









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Binding to Business Objects and Generic List
ME

2006-06-04, 7:05 pm

I have an object we'll call it MyObject. MyObject has a property calld
MyBusinessObjects of type List<IMyBusinessObject2>. IMyBusinessObject2 is a
defined interface in my application (See below). I want to bind the
MyBusinessObjects property to a ComboBox as follows:

ComboBox cbData = new ComboBox();
BindingSource bsSource = new BindingSource();

bsSource.DataSource = MyObject.MyBusinessObjects;
cbData.DisplayMemeber = "Text";
cbData.ValueMember = "Index";

cbData.DataSource = bsSource;


When I run the code I get just the type name (like
'namespace.MyBusinessObjects') of the object in the drop down or I will get
an error that says that the field "Text" does not exist. However if I
change the object in the collection to use the base interface
(IMyBusinessObject) it works fine. How can I bind a control to a business
object that uses an extended interface?

Thanks,

Matt

---------------------------------------------------
public interface IMyBusinessObject2 : IMyBusinessObject
{

}

public interface IMyBusinessObject
{
int Index
{
get;
set;
}
string Text
{
get;
set;
}
}


SP

2006-06-04, 10:05 pm


"ME" <trash.trash@comcast.netREMOVETHIS> wrote in message
news:PNGdnX-4nq5xtR7ZRVn-tg@comcast.com...
>I have an object we'll call it MyObject. MyObject has a property calld
>MyBusinessObjects of type List<IMyBusinessObject2>. IMyBusinessObject2 is
>a defined interface in my application (See below). I want to bind the
>MyBusinessObjects property to a ComboBox as follows:
>
> ComboBox cbData = new ComboBox();
> BindingSource bsSource = new BindingSource();
>
> bsSource.DataSource = MyObject.MyBusinessObjects;
> cbData.DisplayMemeber = "Text";
> cbData.ValueMember = "Index";
>
> cbData.DataSource = bsSource;
>
>
> When I run the code I get just the type name (like
> 'namespace.MyBusinessObjects') of the object in the drop down or I will
> get an error that says that the field "Text" does not exist. However if I
> change the object in the collection to use the base interface
> (IMyBusinessObject) it works fine. How can I bind a control to a business
> object that uses an extended interface?


I have run into this problem a long time ago. You will probably have to add
the declarations that you want the databinding to see to the
IMyBusinessObject2 interface with the new keyword. Some databinding does
not find the members defined in the inherited interfaces.

SP

>
> Thanks,
>
> Matt
>
> ---------------------------------------------------
> public interface IMyBusinessObject2 : IMyBusinessObject
> {
>
> }
>
> public interface IMyBusinessObject
> {
> int Index
> {
> get;
> set;
> }
> string Text
> {
> get;
> set;
> }
> }
>



ME

2006-06-04, 10:05 pm

Could you give an example of what you mean? I don't follow how the "new"
keyword will assist.

Thanks,

Matt
"SP" <ecneserpegats@hotmail.com> wrote in message
news:e$iAlIEiGHA.1260@TK2MSFTNGP05.phx.gbl...
>
> "ME" <trash.trash@comcast.netREMOVETHIS> wrote in message
> news:PNGdnX-4nq5xtR7ZRVn-tg@comcast.com...
>
> I have run into this problem a long time ago. You will probably have to
> add the declarations that you want the databinding to see to the
> IMyBusinessObject2 interface with the new keyword. Some databinding does
> not find the members defined in the inherited interfaces.
>
> SP
>
>
>



SP

2006-06-05, 10:02 pm


"ME" <trash.trash@comcast.netREMOVETHIS> wrote in message
news:mZCdnVzWfcQlEB7ZnZ2dnUVZ_tSdnZ2d@co
mcast.com...
> Could you give an example of what you mean? I don't follow how the "new"
> keyword will assist.


The new keyword just stops you from getting a compilation warning. Any
declarations in your IMyBusinessObject interface that you want to bind to
need to be added to your IMyBusinessObject2 interface .

SP
>
> Thanks,
>
> Matt
> "SP" <ecneserpegats@hotmail.com> wrote in message
> news:e$iAlIEiGHA.1260@TK2MSFTNGP05.phx.gbl...
>
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com