Reputation: 289
Infragistics documentation beats me,
All I want to do is to hydrate a ultraDataSource with a List
I'm currently using onload to set uDataSource1.Rows.SetCount(list.count) and do the fill in event handler private void uDataSource1_CellDataRequested(object sender, Infragistics.Win.UltraWinDataSource.CellDataRequestedEventArgs e) { FillGrid(sender,e); } How do I bind this ultraDataSource to the list object so that on a button click I can accept the changed list as the new ultraDataSource hydrator? A proper usage is hard to find.
Note I need the headers in the table to have proper captions and other column properties (such as load on demand) which are the core advantages of ultraDataSource. Any tips would help
Upvotes: 0
Views: 1899
Reputation: 206
Note that you only need to use an UltraDataSource if you want the grid to load the data on-demand.
Another, much simpler option, would be to bind the grid directly to the List. The grid can bind to any object that implements IList or IBindingList.
Upvotes: 1
Reputation: 2120
To force UltraDataSource to fire ListChanged you can call this overload of the SetCount method in your button click event:
public void SetCount(
int newCount,
bool forceNotifyListReset
)
More info relate to this method you can find here
However this will only work if you have set the columns of the band of UltraDataSource beforehand. If your ICollection contains different objects each time you need a little reflection to set the columns like this:
foreach (var property in typeof(MyClass).GetProperties().ToList())
{
this.ultraDataSource1.Band.Columns.Add(property.Name);
}
Keep in mind setting cells values in this scenario can by tricky and will require more reflections in CellDataRequested event handler like this:
var cellValue = ((List<MyClass>)data)[e.Row.Index];
e.Data = cellValue.GetType().GetProperty(e.Column.Key).GetValue(cellValue, null);
Upvotes: 2