|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Using Objects as Data SourcesI'm able to add a an object to my project as a datasource by using the Data Source Configuration Wizard, but can't seem to make it do anything. For example when I bind a list<> object to a DataGridView control a BindingSource and BindingNavigator are created as I expected, but when data is entered into the columns of the grid, they disappear as soon as I move out of the cell. I suspect this is because I have not prepared the object properly for databinding, but I can't find anything that describes how objects that are to be databound are to be constructed. Can anyone tell me where I can find some information on designing objects that will be used for databinding? Thanks, Otis Mukinfus http://www.otismukinfus.com http://www.tomchilders.com Let me know if you find anything (let us all know). AFAICT this is very
lightly documented. -- Show quote____________________________________ William (Bill) Vaughn Author, Mentor, Consultant Microsoft MVP INETA Speaker www.betav.com/blog/billva www.betav.com Please reply only to the newsgroup so that others can benefit. This posting is provided "AS IS" with no warranties, and confers no rights. __________________________________ "Otis Mukinfus" <ph***@emailaddress.com> wrote in message news:2kc0s1dcpduioasg4q2gnhbab9dcmqbb6e@4ax.com... > VS 2005 has the option of using objects as datasources. > > I'm able to add a an object to my project as a datasource by using the > Data Source Configuration Wizard, but can't seem to make it do > anything. For example when I bind a list<> object to a DataGridView > control a BindingSource and BindingNavigator are created as I > expected, but when data is entered into the columns of the grid, they > disappear as soon as I move out of the cell. > > I suspect this is because I have not prepared the object properly for > databinding, but I can't find anything that describes how objects that > are to be databound are to be constructed. > > Can anyone tell me where I can find some information on designing > objects that will be used for databinding? > > Thanks, > > Otis Mukinfus > http://www.otismukinfus.com > http://www.tomchilders.com This is one way that I know you can have design time support for objects.
There may be other ways to do this, but this works. 1. Create a class library project 2. Create your class with public properties 3. Create a separate Collections Class that inherits a bindinglist of class you just made (Inherits BindingList(of employees) 4. use the imports statement at the top of your collections class and import the System.ComponentModel name space. This is the first step for design time databinding. 5. Under the Inherits statement you added, add 'Implements IComponent' You will have to add finalizers and Sort methods of your own. You should also add events for text public properties so that updates in your classes will be reflected in your bound controls. There is some great source code for these kinds of projects including how to add sorting logic. 1.1 and 2.0 frame work take a look at this. http://msdn.microsoft.com/msdnmag/issues/05/08/CollectionsandDataBinding/default.aspx -- Show quoteSteven "William (Bill) Vaughn" wrote: > Let me know if you find anything (let us all know). AFAICT this is very > lightly documented. > > -- > ____________________________________ > William (Bill) Vaughn > Author, Mentor, Consultant > Microsoft MVP > INETA Speaker > www.betav.com/blog/billva > www.betav.com > Please reply only to the newsgroup so that others can benefit. > This posting is provided "AS IS" with no warranties, and confers no rights. > __________________________________ > > "Otis Mukinfus" <ph***@emailaddress.com> wrote in message > news:2kc0s1dcpduioasg4q2gnhbab9dcmqbb6e@4ax.com... > > VS 2005 has the option of using objects as datasources. > > > > I'm able to add a an object to my project as a datasource by using the > > Data Source Configuration Wizard, but can't seem to make it do > > anything. For example when I bind a list<> object to a DataGridView > > control a BindingSource and BindingNavigator are created as I > > expected, but when data is entered into the columns of the grid, they > > disappear as soon as I move out of the cell. > > > > I suspect this is because I have not prepared the object properly for > > databinding, but I can't find anything that describes how objects that > > are to be databound are to be constructed. > > > > Can anyone tell me where I can find some information on designing > > objects that will be used for databinding? > > > > Thanks, > > > > Otis Mukinfus > > http://www.otismukinfus.com > > http://www.tomchilders.com > > > On Sun, 8 Jan 2006 01:57:01 -0800, Steven Ramacher
<sramacher@community.nospam> wrote: Show quote >This is one way that I know you can have design time support for objects. Thanks for the suggestion Steven. I did try using A class that>There may be other ways to do this, but this works. > >1. Create a class library project >2. Create your class with public properties >3. Create a separate Collections Class that inherits a bindinglist of class >you just made (Inherits BindingList(of employees) >4. use the imports statement at the top of your collections class and >import the System.ComponentModel name space. This is the first step for >design time databinding. > >5. Under the Inherits statement you added, add 'Implements IComponent' > >You will have to add finalizers and Sort methods of your own. You should >also add events for text public properties so that updates in your classes >will be reflected in your bound controls. There is some great source code for >these kinds of projects including how to add sorting logic. > >1.1 and 2.0 frame work take a look at this. >http://msdn.microsoft.com/msdnmag/issues/05/08/CollectionsandDataBinding/default.aspx inherits from IBindingList<T>, but that didn't work either. I'm still researching this. If I find the way or if someone tells me the way, I'll post it here. Otis Mukinfus http://www.otismukinfus.com http://www.tomchilders.com On Sun, 08 Jan 2006 13:00:28 -0600, Otis Mukinfus
<ph***@emailaddress.com> wrote: Show quote >On Sun, 8 Jan 2006 01:57:01 -0800, Steven Ramacher By the way Steven, I don't care if it does design time binding. It><sramacher@community.nospam> wrote: > >>This is one way that I know you can have design time support for objects. >>There may be other ways to do this, but this works. >> >>1. Create a class library project >>2. Create your class with public properties >>3. Create a separate Collections Class that inherits a bindinglist of class >>you just made (Inherits BindingList(of employees) >>4. use the imports statement at the top of your collections class and >>import the System.ComponentModel name space. This is the first step for >>design time databinding. >> >>5. Under the Inherits statement you added, add 'Implements IComponent' >> >>You will have to add finalizers and Sort methods of your own. You should >>also add events for text public properties so that updates in your classes >>will be reflected in your bound controls. There is some great source code for >>these kinds of projects including how to add sorting logic. >> >>1.1 and 2.0 frame work take a look at this. >>http://msdn.microsoft.com/msdnmag/issues/05/08/CollectionsandDataBinding/default.aspx > >Thanks for the suggestion Steven. I did try using A class that >inherits from IBindingList<T>, but that didn't work either. > >I'm still researching this. If I find the way or if someone tells me >the way, I'll post it here. > > >Otis Mukinfus >http://www.otismukinfus.com >http://www.tomchilders.com just needs to do runtime binding. Otis Mukinfus http://www.otismukinfus.com http://www.tomchilders.com Show me an example of your code. I mostly use generic collection instead of
array list, data tables, and datasets and that seems to work well. One question, are you making class libraries and compiling it to a dll or are you just creating a class? You should bind to an iList interface that exposed the collection that you created. -- Show quoteSteven "Otis Mukinfus" wrote: > On Sun, 08 Jan 2006 13:00:28 -0600, Otis Mukinfus > <ph***@emailaddress.com> wrote: > > >On Sun, 8 Jan 2006 01:57:01 -0800, Steven Ramacher > ><sramacher@community.nospam> wrote: > > > >>This is one way that I know you can have design time support for objects. > >>There may be other ways to do this, but this works. > >> > >>1. Create a class library project > >>2. Create your class with public properties > >>3. Create a separate Collections Class that inherits a bindinglist of class > >>you just made (Inherits BindingList(of employees) > >>4. use the imports statement at the top of your collections class and > >>import the System.ComponentModel name space. This is the first step for > >>design time databinding. > >> > >>5. Under the Inherits statement you added, add 'Implements IComponent' > >> > >>You will have to add finalizers and Sort methods of your own. You should > >>also add events for text public properties so that updates in your classes > >>will be reflected in your bound controls. There is some great source code for > >>these kinds of projects including how to add sorting logic. > >> > >>1.1 and 2.0 frame work take a look at this. > >>http://msdn.microsoft.com/msdnmag/issues/05/08/CollectionsandDataBinding/default.aspx > > > >Thanks for the suggestion Steven. I did try using A class that > >inherits from IBindingList<T>, but that didn't work either. > > > >I'm still researching this. If I find the way or if someone tells me > >the way, I'll post it here. > > > > > >Otis Mukinfus > >http://www.otismukinfus.com > >http://www.tomchilders.com > > By the way Steven, I don't care if it does design time binding. It > just needs to do runtime binding. > > Otis Mukinfus > http://www.otismukinfus.com > http://www.tomchilders.com > On Sun, 8 Jan 2006 16:03:02 -0800, Steven Ramacher
<sramacher@community.nospam> wrote: >Show me an example of your code. I mostly use generic collection instead of It's in the attachment.>array list, data tables, and datasets and that seems to work well. One >question, are you making class libraries and compiling it to a dll or are you >just creating a class? You should bind to an iList interface that exposed the >collection that you created. Thanks, Otis Mukinfus http://www.otismukinfus.com http://www.tomchilders.com I looking at what you are trying to do, the only way I can see it work is by
making and compiling a class library that has you business object. Then you add it to your toolbox and then you can bind to it. There is probably other ways, but that is the one that I have gotten to work. I am sorry that I could not have been of more assistance. -- Show quoteSteven "Otis Mukinfus" wrote: > On Sun, 8 Jan 2006 16:03:02 -0800, Steven Ramacher > <sramacher@community.nospam> wrote: > > >Show me an example of your code. I mostly use generic collection instead of > >array list, data tables, and datasets and that seems to work well. One > >question, are you making class libraries and compiling it to a dll or are you > >just creating a class? You should bind to an iList interface that exposed the > >collection that you created. > > It's in the attachment. > Thanks, > > > Otis Mukinfus > http://www.otismukinfus.com > http://www.tomchilders.com > Otis Mukinfus wrote:
Show quote > On Sun, 8 Jan 2006 01:57:01 -0800, Steven Ramacher Design time databinding doesn't support generics. So you always have> <sramacher@community.nospam> wrote: > > > This is one way that I know you can have design time support for > > objects. There may be other ways to do this, but this works. > > > > 1. Create a class library project > > 2. Create your class with public properties > > 3. Create a separate Collections Class that inherits a bindinglist > > of class you just made (Inherits BindingList(of employees) > > 4. use the imports statement at the top of your collections class > > and import the System.ComponentModel name space. This is the first > > step for design time databinding. > > > > 5. Under the Inherits statement you added, add 'Implements > > IComponent' > > > > You will have to add finalizers and Sort methods of your own. You > > should also add events for text public properties so that updates > > in your classes will be reflected in your bound controls. There is > > some great source code for these kinds of projects including how to > > add sorting logic. > > > > 1.1 and 2.0 frame work take a look at this. > > http://msdn.microsoft.com/msdnmag/issues/05/08/CollectionsandDataBin > > ding/default.aspx > > Thanks for the suggestion Steven. I did try using A class that > inherits from IBindingList<T>, but that didn't work either. > > I'm still researching this. If I find the way or if someone tells me > the way, I'll post it here. to use a class that's NOT generic. I'm not sure what exactly you're trying to add. A general class that implements IList can be used as a datasource but if you want to pop-up a designer, the datasources won't help you as vs.net doesn't call anything on those when dragged onto a form. FB -- ------------------------------------------------------------------------ Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com My .NET blog: http://weblogs.asp.net/fbouma Microsoft MVP (C#) ------------------------------------------------------------------------ If you looked at the mentioned article it is kind of a hybrid. This uses a
generic collection that is a bindinglist(of t) that they hard code the class into. It works quiet nicely in a design time environment. It uses generics to achieve the desired results, but is not a pure generic base. I have used a similar approach on many projects as I like to control as much of the code as possible. In the mentioned article there are 2 projects, one which gives design time support for objects that he attempts to make strongly typed, and one for generics. http://msdn.microsoft.com/msdnmag/issues/05/08/CollectionsandDataBinding/default.aspx -- Show quoteSteven "Frans Bouma [C# MVP]" wrote: > Otis Mukinfus wrote: > > > On Sun, 8 Jan 2006 01:57:01 -0800, Steven Ramacher > > <sramacher@community.nospam> wrote: > > > > > This is one way that I know you can have design time support for > > > objects. There may be other ways to do this, but this works. > > > > > > 1. Create a class library project > > > 2. Create your class with public properties > > > 3. Create a separate Collections Class that inherits a bindinglist > > > of class you just made (Inherits BindingList(of employees) > > > 4. use the imports statement at the top of your collections class > > > and import the System.ComponentModel name space. This is the first > > > step for design time databinding. > > > > > > 5. Under the Inherits statement you added, add 'Implements > > > IComponent' > > > > > > You will have to add finalizers and Sort methods of your own. You > > > should also add events for text public properties so that updates > > > in your classes will be reflected in your bound controls. There is > > > some great source code for these kinds of projects including how to > > > add sorting logic. > > > > > > 1.1 and 2.0 frame work take a look at this. > > > http://msdn.microsoft.com/msdnmag/issues/05/08/CollectionsandDataBin > > > ding/default.aspx > > > > Thanks for the suggestion Steven. I did try using A class that > > inherits from IBindingList<T>, but that didn't work either. > > > > I'm still researching this. If I find the way or if someone tells me > > the way, I'll post it here. > > Design time databinding doesn't support generics. So you always have > to use a class that's NOT generic. > > I'm not sure what exactly you're trying to add. A general class that > implements IList can be used as a datasource but if you want to pop-up > a designer, the datasources won't help you as vs.net doesn't call > anything on those when dragged onto a form. > > FB > > -- > ------------------------------------------------------------------------ > Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com > My .NET blog: http://weblogs.asp.net/fbouma > Microsoft MVP (C#) > ------------------------------------------------------------------------ > On Sat, 7 Jan 2006 15:17:50 -0800, "William \(Bill\) Vaughn"
<billvaRemoveT***@nwlink.com> wrote: >Let me know if you find anything (let us all know). AFAICT this is very Boy you're sure right about that, Bill!>lightly documented. I tried making the object that was being put in the List<T> object use the IEditableObject interface, but strangely that made it worse. now it won't even show the data in the List<T> objects :0( Joel Murach (Main Frame books writer) has a book out titled "ASP.NET 2.0 Upgrader's Guide" that devotes a chapter to "ObjectDataSources", but the examples and the VS 2005 help seems to indicate what he is writing about only applies to ASP.NET. All of his examples use an ASP.NET control named "ObjectDataSource" to bind to objects that are designed to be used by that control. Some times I think MS has forgotten there are still folks developing Windows applications who would benefit from some of the gadgets they have for ASP.NET. I'll let you know if I learn how to use the objects for binding in windows apps. Otis Mukinfus http://www.otismukinfus.com http://www.tomchilders.com This may help, though I'm a bit late to this thread.
1. Define your class 2. Add BindingSource to Form 3. In IDE, set DataSource of the BindingSource to the Class 4. Set the DataSource of your DataGridView to the BindingSource 4. In code, at Form Load, create your class instances and populate a List(Of yourclass) with the instances. 5. set the DataSource of the BindingSource to be the List(Of yourclass) This works well for me, both for display and editing the data. If you re-populate the List(Of ), you must do it something like: ' Clear it out If bsSolutions.DataSource Is slns Then 'needed check for first time thru bsSolutions.Clear() End If 'Whatever it takes to rebuild the List(Of ) bsSolutions.DataSource = slns bsSolutions.ResetBindings(False) 'To make controls(s) update content Speaking of inadequate documentation ... Now try to find out how to do ColumnClick sorts on the DataGridView. The key to all of this is to do as much as possible (preferably all) thru the BindingSource -- which makes Data Validation follow a different line than you might initially think. (consider the BindingComplete event for data validation). -- Show quoteJim Parsells "Otis Mukinfus" wrote: > On Sat, 7 Jan 2006 15:17:50 -0800, "William \(Bill\) Vaughn" > <billvaRemoveT***@nwlink.com> wrote: > > >Let me know if you find anything (let us all know). AFAICT this is very > >lightly documented. > > Boy you're sure right about that, Bill! > > I tried making the object that was being put in the List<T> object use > the IEditableObject interface, but strangely that made it worse. now > it won't even show the data in the List<T> objects :0( > > Joel Murach (Main Frame books writer) has a book out titled "ASP.NET > 2.0 Upgrader's Guide" that devotes a chapter to "ObjectDataSources", > but the examples and the VS 2005 help seems to indicate what he is > writing about only applies to ASP.NET. All of his examples use an > ASP.NET control named "ObjectDataSource" to bind to objects that are > designed to be used by that control. > > Some times I think MS has forgotten there are still folks developing > Windows applications who would benefit from some of the gadgets they > have for ASP.NET. > > I'll let you know if I learn how to use the objects for binding in > windows apps. > > Otis Mukinfus > http://www.otismukinfus.com > http://www.tomchilders.com > I'm even later, but I came across this blog entry that takes you throug the
whole process. It worked for me http://blogs.msdn.com/vbteam/archive/2005/04/14/TableAdaptersAndObjects.aspx Show quote "Jim Parsells" wrote: > This may help, though I'm a bit late to this thread. > 1. Define your class > 2. Add BindingSource to Form > 3. In IDE, set DataSource of the BindingSource to the Class > 4. Set the DataSource of your DataGridView to the BindingSource > 4. In code, at Form Load, create your class instances and populate a List(Of > yourclass) with the instances. > 5. set the DataSource of the BindingSource to be the List(Of yourclass) > > This works well for me, both for display and editing the data. If you > re-populate the List(Of ), you must do it something like: > ' Clear it out > If bsSolutions.DataSource Is slns Then 'needed check for first time > thru > bsSolutions.Clear() > End If > 'Whatever it takes to rebuild the List(Of ) > > bsSolutions.DataSource = slns > bsSolutions.ResetBindings(False) 'To make controls(s) update > content > > Speaking of inadequate documentation ... Now try to find out how to do > ColumnClick sorts on the DataGridView. > > The key to all of this is to do as much as possible (preferably all) thru > the BindingSource -- which makes Data Validation follow a different line than > you might initially think. (consider the BindingComplete event for data > validation). > -- > Jim Parsells > > > "Otis Mukinfus" wrote: > > > On Sat, 7 Jan 2006 15:17:50 -0800, "William \(Bill\) Vaughn" > > <billvaRemoveT***@nwlink.com> wrote: > > > > >Let me know if you find anything (let us all know). AFAICT this is very > > >lightly documented. > > > > Boy you're sure right about that, Bill! > > > > I tried making the object that was being put in the List<T> object use > > the IEditableObject interface, but strangely that made it worse. now > > it won't even show the data in the List<T> objects :0( > > > > Joel Murach (Main Frame books writer) has a book out titled "ASP.NET > > 2.0 Upgrader's Guide" that devotes a chapter to "ObjectDataSources", > > but the examples and the VS 2005 help seems to indicate what he is > > writing about only applies to ASP.NET. All of his examples use an > > ASP.NET control named "ObjectDataSource" to bind to objects that are > > designed to be used by that control. > > > > Some times I think MS has forgotten there are still folks developing > > Windows applications who would benefit from some of the gadgets they > > have for ASP.NET. > > > > I'll let you know if I learn how to use the objects for binding in > > windows apps. > > > > Otis Mukinfus > > http://www.otismukinfus.com > > http://www.tomchilders.com > > |
|||||||||||||||||||||||