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
210
Dynamic Datasource Columns in UltraGrid
posted

Hi,

I'm looking to bind an ultragrid to a dynamic datasource. The source of my data is found in a list of "prices" objects, which have Properties holding the numbers I want displayed.

It would work perfectly to create an object MyDataRow which would encapsulate some of the "prices" objects, and expose one property for each column.

That way I could use a BindingList of MyDataRow objects, and each column would be nicely bound to the UltraGrid, with a proper INotifyPropertyChanged implementation to insure the grid refreshes when my underying "prices" change.

However, one of my constraints is that I need to dynamically add columns at run time. That seems to be a problem.

Indeed, since on this architecture a column is necessarily a Property of the MyDataRow object, I cannot dynamically modify the class to add Properties, and then fill all the existing instances...

How can I get around this problem, and properly have BOTH Databinding to object properties AND dynamic column creation in an ultragrid?

Parents
No Data
Reply
  • 469350
    Offline posted

    Hi,

    I'm not entirely sure I understand what you are trying to do.How do you intend to make your prices object vary it's own properties? Even without considering the grid or data binding, there is no way to do this. So how do you intend to define your data structure and add properties to it?

    So I don't see any way to do this using a custom-defined object like a "Prices" object that you create yourself.

    It sounds to me like what you need is to use some other data source which has the ability to dynamically add and remove columns. A DataTable/DataSet has this ability, as does the UltraDataSource component.

    Actually.... what I said above is not really true. There is a way to have an object that dynmically adds and removes bound columns to itself. Obviously there is, since Datatable, DataSet, and UltraDataSource do it. They way they do this is by implementing IBindingList and ITypedList. But it doesn't make a lot of sense for you to re-invent the wheel here when there are perfectly good objects already in place that will do this for you.

    My advice would be to use an UltraDataSource, since it seems like you have a pretty simple set of data here without any hierarchy and without dynamically-changing relationships. 

Children