I have a snippet of sandbox code I'm trying to make work:
***************************
foos.Add(new Foo(1, 1));
foos.Add(
//What's the best way to get my Foo objects into the ultraDataSource?
ultraGrid1.DataSource = ultraDataSource1;
************************
I know I can manually add rows to the ultraDataSource but that would require iterating over the collection. Is that the only way to add to an UltraDataSource?
To back up a bit... the larger problem I'm simulating in my sandbox is that Foo has two properties, X and Y. I want a grid with ONLY ONE column, X. I'm assuming that the UltraDataSource is the way to go here. Is that assumption wrong. Should I skin this cat another way?
[Edit: My code got a little chomped somehow, I just made it readable]
Yeah, there were some know performance issues when you bind with a hierarchy that were introduced with the release of CLR2. But I'm not sure those issues still exist. I haven't heard anyone report them in quite a while. And I'm not sure they apply to flat data sources or anything other than DataTable/DataSet.
A flat BindingList is probably safe enough to use without a BindingSource.
The only reason I always lean towards using a binding source is I've seen other posts where other people have run into problems with direct binding so it's more of a self formed habit.
This is perfectly valid:
ultraGrid1.DataSource = foos;
You could wrap it in a BindingSource as Steve suggests.But I'm not sure you need to.
The only down-side of this is that a List<T> isn't really meant for binding, so it lacks some functionality. For example, you probably won't be able to add rows to the grid. And the grid will not be notified of changes when new rows are added to the list.
A better way to do this would be to use BindingList<T>, instead of List<T>. BindingLists are made for binding and send all the proper notifications that a bound control expects.
I believe the best thing to do would be to assign foo to a binding source and then assign the binding source to your grid. Then you could hide Y in the grid so only X is displayed. If you were going to use foo with an UltraDataSource you would basically have to define the structure of foo and then add your foo objects to the UltraDataSource sort of like it was a data table. I don't think that is your intent so that probably isn't the way to go.