Vibrant discussion about CSLA .NET and using the framework to build great business applications.
Yes. You need to implement INotifyProopertyChanged interface inside your ROB.
ROBInstance: BB< ROBInstance>, INotifyPropertyChanged
Sergey Barskiy
Principal Consultant
office: 678.405.0687 | mobile: 404.388.1899
Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation
From: Michael [mailto:cslanet@lhotka.net] Sent: Tuesday, June 09, 2009 12:01 AM To: Sergey Barskiy Subject: [CSLA .NET] Selectable read only objects
I often need to bind a ROL of ROB to a WinForms grid with the ability to select items via a CheckBoxColumn. The set in the following property never gets hit when the cell is clicked: bool m_selected; public bool Selected { get { return m_selected; } set { m_selected = value; OnPropertyChanged("Selected"); } } The code does work if the ROB is change to a BB. Has anyone else tried something like this? Regards Michael
sergeyb:Yes. You need to implement INotifyProopertyChanged interface inside your ROB. ROBInstance: BB< ROBInstance>, INotifyPropertyChanged
Yeah but I don't think lack of INotifyPropertyChanged explains why Michael's set code never runs. It means that the UI won't automatically know about the change if the property is updated in code. I've done something similar, blurring the definition of read only so I don't know why it's not working. I can bind any plain old object to a grid and the properties get updated (i.e, set runs) when edited in the grid.
Have you tried a simple List<ROB> or even an array? Does the set work then? That would indicate whether or not it's really related to the ROL or something else.
Your problem is most likely caused by the fact that the ReadOnlyListBase or, more specifically, the Core.ReadOnlyBindingList class it inherits is marked as read-only be default. When you bind the object to a UI control, such as a DataGrid, the control looks at the IBindingList interface to determine what behaviors are supported. This includes the IsReadOnly property (from IList) as well as AllowEdit, AllowNew and AllowRemove. The latter three are set to false by default.
If you want a control to allow users to toggle your Selected property, you'll need to either override the AllowEdit property or set it to true in your constructor. I believe you may also need to change IsReadOnly to false, but try changing AllowEdit first to be sure. You will most likely need to apply the Bindable attribute to your business object so that other properties can't be edited in the UI.
Hope this helps.
I've spent the last few days upgrading our projects from CSLA 3.8 to 4.3. Sadly, all of our selectable ReadOnlyBase / ReadOnlyListBase collections bound to WinForms DataGridViews are broken. When I first asked this question, the problem was in the ROLB; binding to a plain List<T> of ROB behaved correctly. However, with 4.3 even binding to a plain List does not work. So, that makes me wonder if the problem is in ROB.
When programatically changing the Selected field for all items, only the binding source's current item responds to the OnPropertyChanged (the check box for the current row is updated correctly). No other rows respond. When a different row is clicked, its check box is updated. So, what's different?
I know this is an old thread, so If I don't get any help here I'll start a new one.
RegardsMichael
For Windows Forms with CSLA 4.3 you must change to use the BindingList derived base class:
ReadOnlyBindingListBase andBusinessListBindingListBase etc
The ReadOnlyListBase and BusinessListBase is now derived from ObservableCollection that does not work properly with Windows Forms.
Jonny Bekkum, Norway CslaContrib Coordinator
Fantastic, thanks Jonny!