Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
315
Using UltraDataSource on collections of objects
posted

I have a snippet of sandbox code I'm trying to make work:

*************************** 

 

 

List<Foo> foos = new List<Foo>();

foos.Add(new Foo(1, 1));

foos.Add(

 

new Foo(2, 2));  

//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]

Parents
No Data
Reply
  • 469350
    Verified Answer
    Offline posted

    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.

     

Children