473,804 Members | 3,399 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Binding to Business Objects and Generic List

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

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

bsSource.DataSo urce = MyObject.MyBusi nessObjects;
cbData.DisplayM emeber = "Text";
cbData.ValueMem ber = "Index";

cbData.DataSour ce = bsSource;
When I run the code I get just the type name (like
'namespace.MyBu sinessObjects') 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
(IMyBusinessObj ect) it works fine. How can I bind a control to a business
object that uses an extended interface?

Thanks,

Matt

---------------------------------------------------
public interface IMyBusinessObje ct2 : IMyBusinessObje ct
{

}

public interface IMyBusinessObje ct
{
int Index
{
get;
set;
}
string Text
{
get;
set;
}
}
Jun 4 '06 #1
5 7905
"ME" <tr*********@co mcast.netREMOVE THIS> wrote in message
news:PN******** ************@co mcast.com...
I have an object we'll call it MyObject. MyObject has a property calld
MyBusinessObje cts of type List<IMyBusines sObject2>. IMyBusinessObje ct2 is
a defined interface in my application (See below). I want to bind the
MyBusinessObje cts property to a ComboBox as follows:

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

bsSource.DataSo urce = MyObject.MyBusi nessObjects;
cbData.DisplayM emeber = "Text";
cbData.ValueMem ber = "Index";

cbData.DataSour ce = bsSource;
When I run the code I get just the type name (like
'namespace.MyBu sinessObjects') 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
(IMyBusinessObj ect) it works fine. How can I bind a control to a business
object that uses an extended interface?


I've no idea why it doesn't work (though I'd very much like to know!). The
only workround I've found is rather nasty - convert the list to a
List<IMyBusines sObject> before binding, e.g.:

Converter<IMyBu sinessObject2, IMyBusinessObje ct> conv = delegate
(IMyBusinessObj ect2 obj) { return obj; };
bsSource.DataSo urce =
MyObject.MyBusi nessObjects.Con vertAll<IMyBusi nessObject>(con v);

Chris Jobson
Jun 4 '06 #2
ME
So I would have to conclude that to be a bug in .NET 2 then. If say the
"Text" property was defined in IMyBusinessObje ct and the "Index" property
was defined in IMyBusinessObje ct2 one would be pretty much up the creek with
out a paddle. This has BIG implications when you need to do this type of
binding to a DataGridView.

Thanks,

Matt
"Chris Jobson" <ch**********@b tinternet.com> wrote in message
news:ey******** *****@TK2MSFTNG P05.phx.gbl...
"ME" <tr*********@co mcast.netREMOVE THIS> wrote in message
news:PN******** ************@co mcast.com...
I have an object we'll call it MyObject. MyObject has a property calld
MyBusinessObj ects of type List<IMyBusines sObject2>. IMyBusinessObje ct2 is
a defined interface in my application (See below). I want to bind the
MyBusinessObj ects property to a ComboBox as follows:

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

bsSource.DataSo urce = MyObject.MyBusi nessObjects;
cbData.DisplayM emeber = "Text";
cbData.ValueMem ber = "Index";

cbData.DataSour ce = bsSource;
When I run the code I get just the type name (like
'namespace.MyBu sinessObjects') 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
(IMyBusinessObj ect) it works fine. How can I bind a control to a
business object that uses an extended interface?


I've no idea why it doesn't work (though I'd very much like to know!). The
only workround I've found is rather nasty - convert the list to a
List<IMyBusines sObject> before binding, e.g.:

Converter<IMyBu sinessObject2, IMyBusinessObje ct> conv = delegate
(IMyBusinessObj ect2 obj) { return obj; };
bsSource.DataSo urce =
MyObject.MyBusi nessObjects.Con vertAll<IMyBusi nessObject>(con v);

Chris Jobson

Jun 4 '06 #3
SP

"ME" <tr*********@co mcast.netREMOVE THIS> wrote in message
news:PN******** ************@co mcast.com...
I have an object we'll call it MyObject. MyObject has a property calld
MyBusinessObje cts of type List<IMyBusines sObject2>. IMyBusinessObje ct2 is
a defined interface in my application (See below). I want to bind the
MyBusinessObje cts property to a ComboBox as follows:

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

bsSource.DataSo urce = MyObject.MyBusi nessObjects;
cbData.DisplayM emeber = "Text";
cbData.ValueMem ber = "Index";

cbData.DataSour ce = bsSource;
When I run the code I get just the type name (like
'namespace.MyBu sinessObjects') 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
(IMyBusinessObj ect) 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
IMyBusinessObje ct2 interface with the new keyword. Some databinding does
not find the members defined in the inherited interfaces.

SP

Thanks,

Matt

---------------------------------------------------
public interface IMyBusinessObje ct2 : IMyBusinessObje ct
{

}

public interface IMyBusinessObje ct
{
int Index
{
get;
set;
}
string Text
{
get;
set;
}
}

Jun 5 '06 #4
ME
Could you give an example of what you mean? I don't follow how the "new"
keyword will assist.

Thanks,

Matt
"SP" <ec***********@ hotmail.com> wrote in message
news:e$******** ******@TK2MSFTN GP05.phx.gbl...

"ME" <tr*********@co mcast.netREMOVE THIS> wrote in message
news:PN******** ************@co mcast.com...
I have an object we'll call it MyObject. MyObject has a property calld
MyBusinessObj ects of type List<IMyBusines sObject2>. IMyBusinessObje ct2 is
a defined interface in my application (See below). I want to bind the
MyBusinessObj ects property to a ComboBox as follows:

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

bsSource.DataSo urce = MyObject.MyBusi nessObjects;
cbData.DisplayM emeber = "Text";
cbData.ValueMem ber = "Index";

cbData.DataSour ce = bsSource;
When I run the code I get just the type name (like
'namespace.MyBu sinessObjects') 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
(IMyBusinessObj ect) 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
IMyBusinessObje ct2 interface with the new keyword. Some databinding does
not find the members defined in the inherited interfaces.

SP

Thanks,

Matt

---------------------------------------------------
public interface IMyBusinessObje ct2 : IMyBusinessObje ct
{

}

public interface IMyBusinessObje ct
{
int Index
{
get;
set;
}
string Text
{
get;
set;
}
}


Jun 5 '06 #5
SP

"ME" <tr*********@co mcast.netREMOVE THIS> wrote in message
news:mZ******** *************** *******@comcast .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 IMyBusinessObje ct interface that you want to bind to
need to be added to your IMyBusinessObje ct2 interface .

SP
Thanks,

Matt
"SP" <ec***********@ hotmail.com> wrote in message
news:e$******** ******@TK2MSFTN GP05.phx.gbl...

"ME" <tr*********@co mcast.netREMOVE THIS> wrote in message
news:PN******** ************@co mcast.com...
I have an object we'll call it MyObject. MyObject has a property calld
MyBusinessOb jects of type List<IMyBusines sObject2>. IMyBusinessObje ct2
is a defined interface in my application (See below). I want to bind the
MyBusinessOb jects property to a ComboBox as follows:

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

bsSource.DataSo urce = MyObject.MyBusi nessObjects;
cbData.DisplayM emeber = "Text";
cbData.ValueMem ber = "Index";

cbData.DataSour ce = bsSource;
When I run the code I get just the type name (like
'namespace.MyBu sinessObjects') 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
(IMyBusinessObj ect) 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
IMyBusinessObje ct2 interface with the new keyword. Some databinding does
not find the members defined in the inherited interfaces.

SP

Thanks,

Matt

---------------------------------------------------
public interface IMyBusinessObje ct2 : IMyBusinessObje ct
{

}

public interface IMyBusinessObje ct
{
int Index
{
get;
set;
}
string Text
{
get;
set;
}
}



Jun 6 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
5065
by: Stuart Hilditch | last post by:
Hi all, I am hoping that someone with some experience developing nTier apps can give me some advice here. I am writing an nTier web app that began with a Data Access Layer (DAL), Business Logic Layer (BLL) and User Interface Layer (UIL). The problem I found with this was circular referencing...
0
1644
by: Michael Rodriguez | last post by:
I have a custom business object collection based on the CSLA.NET framework from Rockfor Lhotka's "Expert C# Business Objects" book. I bound my winform to the object and when I open the screen the records are there and I can scroll through them. The problem is when I call BindingSource.AddNew() it doesn't seem to work. I stepped through the code and a new object is being created, it just doesn't get added to the list. If I manually call...
1
1031
by: Kelly S | last post by:
I have a datagrid that I am binding to a collection of business objects. The datagrid is display only, but I am changing objects in my collection upon selection of one of the items in the datagrid. I want these changes to be reflected in my datagrid, but I don't know how to go about it. I tried re-binding to the collection, but that didn't work. Any suggestions?
10
5103
by: moondaddy | last post by:
I'm new to c# and .net 2.0. In the old vb.net 1.1 days I normally created a list class for every business class and used this list class for all databinding rather than using datasets. This is because often I wanted to edit data in the list and therefore needed to talk to the business object and not the dataset. Since this was a must, I standardized on creating list objects in most cases so everything was standardized. I've searched far...
3
4965
by: Furty | last post by:
Hi, I'm looking for the best practice for creating a generic data validation implementation for my data bound business objects. I currently have a business object base class implementing the following interfaces: IEditableObject, ICloneable, INotifyPropertyChanged, and IDataErrorInfo More specifically, my IDataErrorInfo implementation is like so:
3
6638
by: Harry Haller | last post by:
Hello, I want to implement a generic list which will be used to display 7 columns in a GridView. One should be able to sort, filter and page each of the 7 columns. Ideally the filter should be implemented simultaneously for multiple columns - but the data need only be sorted by a single column at a time. Sorting should be both ascending and descending. I'm currently using a DataView but it's far too slow, because there are a large...
3
1503
by: Arcadefreaque | last post by:
I'm realizing how little I know about C++ today as I try to convert some functionality from VB.Net to C++. I have a procedure that I need to pass a List of objects to, and cannot see how to do this using C++. It's easy in VB.Net, so I'm hoping it is just my silly misunderstanding of c++ that is preventing me from doing this in c++. In VB.Net, to create a couple of objects and add them into a generic list, this is the code that is...
12
3606
by: BillE | last post by:
I'm trying to decide if it is better to use typed datasets or business objects, so I would appreciate any thoughts from someone with more experience. When I use a business object to populate a gridview, for example, I loop through a datareader, populating an array list with instances of a custom class in the middle tier, and then send the array list up to the presentation layer and bind the gridview to it. If I use a typed dataset, I...
4
3032
by: =?Utf-8?B?Z2lkZHk=?= | last post by:
hi, I posted here earlier with a great reply: http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.dotnet.languages.csharp&mid=ed6d7673-0e25-417d-849b-c4b270c76044&sloc=en-us Something like this works nicely: List<Personps = new List<Person>(); ps.Add(new Person("Gideon",15)); CrystalReport11.SetDataSource(ps); crystalReportViewer1.ReportSource = CrystalReport11;
2
2472
by: Andrus | last post by:
Winforms UI assembly has static FormManager.FormCreator method which creates forms taking entity as parameter. I need to pass this method to business objects in business assembly so that business methods can also create forms but does not have reference to UI assembly. I tried code below but got compile errows shown in comments. How to fix ? Andrus.
0
10323
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10310
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10074
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9138
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7613
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6847
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5515
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2983
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.