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
To be a data source the type of the object must implement the IEnumerable interface, which the List<> type does. I'm new to .NET 2.0 but I think the syntax when doing this in code would be like: class Person { public string firstName; pubic string lastName; } List<Person> people= new List<Person>(); person1 = new Person(); person1.firstName = "Steve"; person1.lastName = "Smith"; person2 = new Person(); person2.firstName = "Sue"; person2.lastName = "Sorensen"; people.Add(person1); people.Add(person2); myDatagrid.DataSource = people; myDatagrid.AutoGenerateColumns = true; myDatagrig.DataBind(); I've done this many times using .Net1.1 and it works. I can't tell if there is something wrong with the wizard since I haven't used it. Hope this helps, mortb "Otis Mukinfus" wrote in message news:hevvr1djvm44r7n8st7c8adb5vf7den97u@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