1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2005 Novell, Inc.
23 // Jackson Harper jackson@ximian.com
26 using System.Collections;
27 using System.ComponentModel;
29 namespace System.Windows.Forms {
31 public class PropertyManager : BindingManagerBase {
33 private object data_source;
34 private string property_name;
35 private PropertyDescriptor prop_desc;
36 private bool binding_suspended;
38 internal PropertyManager (object data_source, string property_name)
40 this.data_source = data_source;
41 this.property_name = property_name;
43 prop_desc = TypeDescriptor.GetProperties (data_source).Find (property_name, true);
45 if (prop_desc == null)
46 throw new ArgumentException ("Property does not exist");
47 prop_desc.AddValueChanged (data_source, new EventHandler (PropertyChangedHandler));
50 public override object Current {
51 get { return data_source; }
54 public override int Position {
56 set { /* Doesn't do anything on MS" */ }
59 public override int Count {
63 public override void AddNew ()
65 throw new NotSupportedException ("AddNew is not supported for property to property binding");
68 public override void CancelCurrentEdit ()
70 IEditableObject editable = data_source as IEditableObject;
73 editable.CancelEdit ();
78 public override void EndCurrentEdit ()
82 IEditableObject editable = data_source as IEditableObject;
88 public override PropertyDescriptorCollection GetItemProperties ()
90 return TypeDescriptor.GetProperties (data_source);
93 public override void RemoveAt (int idx)
95 throw new NotSupportedException ("RemoveAt is not supported for property to property binding");
98 public override void ResumeBinding ()
100 binding_suspended = false;
103 public override void SuspendBinding ()
105 binding_suspended = true;
108 protected internal override string GetListName (ArrayList list)
114 protected override void UpdateIsBinding ()
118 protected internal override void OnCurrentChanged (EventArgs e)
122 if (onCurrentChangedHandler != null) {
123 onCurrentChangedHandler (this, e);
127 private void PropertyChangedHandler (object sender, EventArgs e)
129 OnCurrentChanged (EventArgs.Empty);