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,
97 dataRow.GetChildRows (relation));
100 public DataView CreateChildView (string name)
102 return CreateChildView (
103 dataRow.Table.ChildRelations [name]);
106 public void Delete ()
108 dataView.DeleteRowView (this);
112 public void EndEdit ()
114 dataView.EndEditRowView (this);
118 #endregion // Methods
122 public DataView DataView {
123 get { return dataView; }
127 get { return dataRow.IsEditing; }
130 // It becomes true when this instance is created by
131 // DataView.AddNew(). If it is true, then the DataRow is
132 // "Detached", and when this.EndEdit() is invoked, the row
133 // will be added to the table.
135 get { return isNew; }
138 [System.Runtime.CompilerServices.IndexerName("Item")]
139 public object this[string column] {
141 DataColumn dc = dataView.Table.Columns[column];
142 return dataRow[dc, GetActualRowVersion ()];
145 DataColumn dc = dataView.Table.Columns[column];
150 // the compiler creates a DefaultMemeberAttribute from
151 // this IndexerNameAttribute
152 public object this[int column] {
154 DataColumn dc = dataView.Table.Columns[column];
155 return dataRow[dc, GetActualRowVersion ()];
158 DataColumn dc = dataView.Table.Columns[column];
164 private DataRowVersion GetActualRowVersion ()
166 switch (dataView.RowStateFilter) {
167 case DataViewRowState.Added:
168 return DataRowVersion.Proposed;
169 case DataViewRowState.ModifiedOriginal:
170 case DataViewRowState.Deleted:
171 case DataViewRowState.Unchanged:
172 case DataViewRowState.OriginalRows:
173 return DataRowVersion.Original;
174 case DataViewRowState.ModifiedCurrent:
175 return DataRowVersion.Current;
177 return DataRowVersion.Default;
181 get { return dataRow; }
184 public DataRowVersion RowVersion {
191 // It returns the hash code of the DataRow object.
192 public override int GetHashCode ()
194 return dataRow.GetHashCode ();
197 #endregion // Properties
199 #region ICustomTypeDescriptor implementations
202 AttributeCollection ICustomTypeDescriptor.GetAttributes ()
204 System.ComponentModel.AttributeCollection attributes;
205 attributes = AttributeCollection.Empty;
210 string ICustomTypeDescriptor.GetClassName ()
216 string ICustomTypeDescriptor.GetComponentName ()
222 TypeConverter ICustomTypeDescriptor.GetConverter ()
228 EventDescriptor ICustomTypeDescriptor.GetDefaultEvent ()
234 PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty ()
240 object ICustomTypeDescriptor.GetEditor (Type editorBaseType)
246 EventDescriptorCollection ICustomTypeDescriptor.GetEvents ()
248 return new EventDescriptorCollection(null);
252 EventDescriptorCollection ICustomTypeDescriptor.GetEvents (Attribute [] attributes)
254 return new EventDescriptorCollection(null);
258 PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties ()
260 ITypedList typedList = (ITypedList) dataView;
261 return typedList.GetItemProperties(new PropertyDescriptor[0]);
265 PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties (Attribute [] attributes)
267 PropertyDescriptorCollection descriptors;
268 descriptors = ((ICustomTypeDescriptor) this).GetProperties ();
269 // TODO: filter out descriptors which do not contain
270 // any of those attributes
271 // except, those descriptors
272 // that contain DefaultMemeberAttribute
277 object ICustomTypeDescriptor.GetPropertyOwner (PropertyDescriptor pd)
282 #endregion // ICustomTypeDescriptor implementations
284 #region IDataErrorInfo implementation
286 string IDataErrorInfo.Error {
293 string IDataErrorInfo.this[string columnName] {
300 #endregion // IDataErrorInfo implementation