2 // System.Data.DataRowView.cs
5 // Rodrigo Moya <rodrigo@ximian.com>
6 // Miguel de Icaza <miguel@ximian.com>
7 // Daniel Morgan <danmorg@sc.rr.com>
9 // (C) Ximian, Inc 2002
10 // (C) Daniel Morgan 2002
14 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
16 // Permission is hereby granted, free of charge, to any person obtaining
17 // a copy of this software and associated documentation files (the
18 // "Software"), to deal in the Software without restriction, including
19 // without limitation the rights to use, copy, modify, merge, publish,
20 // distribute, sublicense, and/or sell copies of the Software, and to
21 // permit persons to whom the Software is furnished to do so, subject to
22 // the following conditions:
24 // The above copyright notice and this permission notice shall be
25 // included in all copies or substantial portions of the Software.
27 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
31 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
32 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
33 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37 using System.Collections;
38 using System.ComponentModel;
39 using System.Reflection;
44 /// Represents a customized view of a DataRow exposed as a fully featured Windows Forms control.
46 public class DataRowView : ICustomTypeDescriptor, IEditableObject, IDataErrorInfo
52 DataRowVersion rowVersion = DataRowVersion.Current;
60 internal DataRowView (DataView dataView, DataRow row) : this(dataView, row, false){
63 internal DataRowView (DataView dataView, DataRow row, bool isNew) {
64 this.dataView = dataView;
69 #endregion // Constructors
73 public override bool Equals(object other)
75 return (other != null &&
76 other is DataRowView &&
77 ((DataRowView)other).dataRow != null &&
78 ((DataRowView)other).dataRow.Equals(this.dataRow));
81 public void BeginEdit ()
86 public void CancelEdit ()
88 dataView.CancelEditRowView (this);
92 public DataView CreateChildView (DataRelation relation)
95 throw new ArgumentException ("The relation is not parented to the table.");
96 return new DataView (relation.ChildTable);
99 public DataView CreateChildView (string name)
101 return CreateChildView (
102 dataRow.Table.ChildRelations [name]);
105 public void Delete ()
107 dataView.DeleteRowView (this);
111 public void EndEdit ()
113 dataView.EndEditRowView (this);
117 #endregion // Methods
121 public DataView DataView {
122 get { return dataView; }
126 get { return dataRow.IsEditing; }
129 // It becomes true when this instance is created by
130 // DataView.AddNew(). If it is true, then the DataRow is
131 // "Detached", and when this.EndEdit() is invoked, the row
132 // will be added to the table.
134 get { return isNew; }
137 [System.Runtime.CompilerServices.IndexerName("Item")]
138 public object this[string column] {
140 DataColumn dc = dataView.Table.Columns[column];
144 DataColumn dc = dataView.Table.Columns[column];
149 // the compiler creates a DefaultMemeberAttribute from
150 // this IndexerNameAttribute
151 public object this[int column] {
153 DataColumn dc = dataView.Table.Columns[column];
157 DataColumn dc = dataView.Table.Columns[column];
164 get { return dataRow; }
167 public DataRowVersion RowVersion {
174 // It returns the hash code of the DataRow object.
175 public override int GetHashCode ()
177 return dataRow.GetHashCode ();
180 #endregion // Properties
182 #region ICustomTypeDescriptor implementations
185 AttributeCollection ICustomTypeDescriptor.GetAttributes ()
187 System.ComponentModel.AttributeCollection attributes;
188 attributes = AttributeCollection.Empty;
193 string ICustomTypeDescriptor.GetClassName ()
199 string ICustomTypeDescriptor.GetComponentName ()
205 TypeConverter ICustomTypeDescriptor.GetConverter ()
211 EventDescriptor ICustomTypeDescriptor.GetDefaultEvent ()
217 PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty ()
223 object ICustomTypeDescriptor.GetEditor (Type editorBaseType)
229 EventDescriptorCollection ICustomTypeDescriptor.GetEvents ()
231 return new EventDescriptorCollection(null);
235 EventDescriptorCollection ICustomTypeDescriptor.GetEvents (Attribute [] attributes)
237 return new EventDescriptorCollection(null);
241 PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties ()
243 ITypedList typedList = (ITypedList) dataView;
244 return typedList.GetItemProperties(new PropertyDescriptor[0]);
248 PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties (Attribute [] attributes)
250 PropertyDescriptorCollection descriptors;
251 descriptors = ((ICustomTypeDescriptor) this).GetProperties ();
252 // TODO: filter out descriptors which do not contain
253 // any of those attributes
254 // except, those descriptors
255 // that contain DefaultMemeberAttribute
260 object ICustomTypeDescriptor.GetPropertyOwner (PropertyDescriptor pd)
265 #endregion // ICustomTypeDescriptor implementations
267 #region IDataErrorInfo implementation
269 string IDataErrorInfo.Error {
276 string IDataErrorInfo.this[string columnName] {
283 #endregion // IDataErrorInfo implementation