I have an IList of entities bound to my UltraWinGrid. The entity has several get's that return calculated values. These values have to be provided by the user, which they do in a pair of UltraNumericEditors. In order to keep the API as simple as possible, when the user enters these values and presses a button, I copy the values out of the fields and into ivars in the entiries. The get's read those and return the right values.
The numbers are working fine, but the Grid display is not. Unless you take an action that causes a repaint, the cells retain their old values. Little is needed to make them refresh, even mousing over the cells or scrolling will do it.
Since the calculated values are the ones in the Grid, and the ivars are not (normally at least), I put NotifyPropertyChanged calls on the three calculated get's in the set's on the ivars. I thought that would cause the Grid to notice that it had to refresh those columns, but that didn't help.
Any ideas? If nothing else, is there a repaint method I should use?
The problem here is that IList is not a very robust interface for DataBinding. When you make a change to one of you entities, the IList cannot detect this automatically and does not send a notification to the grid that the data has been changed. So the grid does not know to refresh itself.
I recommend using a BindingList<T>, instead of an IList for DataBinding.You may also need to implement INotifyPropertyChanged on your entity class.
Or... if you just want to refresh the grid in code, you can call:
grid.Rows.Refresh(ReloadData)
We did implement INotifyProperChanged, but it seems that is not enough. I'll try a BindingList...
I'd be happy with the refresh. However, we have wrapped the UltraGrid in our own object so we can have a Interface for RhinoMocks. What do I need to expose to get at the .Rows.Refresh? I exposed the Rows as a UltraGridRow (?) but .Refresh doesn't know (ReloadData).
INotifyPropertyChanged won't do anything by itself. Your DataSource (the IList) has to watch for notifications and then raise ListChanged.
Or, like I said, just use a BindingList<T> instead of IList.
Maury Markowitz said:What do I need to expose to get at the .Rows.Refresh? I exposed the Rows as a UltraGridRow (?) but .Refresh doesn't know (ReloadData).
I'm afraid you lost me here. Refresh is on the rows collection, not the row. The ReloadData is an enum.
No (easy) luck on the BindingList, Linq to SQL doesn't seem to like it.