[RESOLVED] DataGridView with a list that doesn't have a parent child relation

[RESOLVED] DataGridView with a list that doesn't have a parent child relation

Old forum URL: forums.lhotka.net/forums/t/1322.aspx


vbdotnetguy posted on Monday, September 25, 2006

how can load items into a DataGridView the way that I would with the BusinessListBase that isn't a parent child relationship?  I have a table that information that I want to load into a grid and be able to add, edit and delete and I thought that I would be able to or i should use the BusinessListBase but I keep getting an error that it can't be added because of it not having parent

RockfordLhotka replied on Monday, September 25, 2006

If you have a set of objects that are not child objects, but you want to put them into a grid, you might just create a BindingList<T> instance:

Dim list As New BindingList(Of yourObjectType)

BindingList<yourObjectType> list = new BindingList<yourObjectType>();

Then add your objects to that collection and use the collection as the data source for your grid.

In version 2.1 there's also the EditableRootListBase, which allows you to create a collection of editable root objects. As changes are made to the collection, they are immediately applied to the objects it contains. In other words, remove an item from the collection, and that item immediately deletes itself from the database. Update an item's data in the collection, and that item is immediately saved to the database (the "child" object's Save() method is called).

vbdotnetguy replied on Monday, September 25, 2006

Thanks Rocky!  I was just coming back to mark this post resolved as I got it figured out, by doing want you suggested.  Just jumped the gun a little to quick.

Copyright (c) Marimer LLC