2 // System.Data.DataRowView.cs
\r
5 // Rodrigo Moya <rodrigo@ximian.com>
\r
6 // Miguel de Icaza <miguel@ximian.com>
\r
7 // Daniel Morgan <danmorg@sc.rr.com>
\r
9 // (C) Ximian, Inc 2002
\r
10 // (C) Daniel Morgan 2002
\r
14 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
\r
16 // Permission is hereby granted, free of charge, to any person obtaining
\r
17 // a copy of this software and associated documentation files (the
\r
18 // "Software"), to deal in the Software without restriction, including
\r
19 // without limitation the rights to use, copy, modify, merge, publish,
\r
20 // distribute, sublicense, and/or sell copies of the Software, and to
\r
21 // permit persons to whom the Software is furnished to do so, subject to
\r
22 // the following conditions:
\r
24 // The above copyright notice and this permission notice shall be
\r
25 // included in all copies or substantial portions of the Software.
\r
27 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\r
28 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\r
29 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
\r
30 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
\r
31 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
\r
32 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
\r
33 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
37 using System.Collections;
\r
38 using System.ComponentModel;
\r
39 using System.Reflection;
\r
41 namespace System.Data
\r
44 /// Represents a customized view of a DataRow exposed as a fully featured Windows Forms control.
\r
46 // FIXME: correct exceptions in this[] methods
\r
47 public partial class DataRowView : IEditableObject {
\r
52 internal DataRowView (DataView dataView, DataRow row, int index)
\r
54 _dataView = dataView;
\r
59 public override bool Equals (object other)
\r
61 return other != null &&
\r
62 other is DataRowView &&
\r
63 ((DataRowView) other)._dataRow != null &&
\r
64 ((DataRowView) other)._dataRow.Equals (_dataRow);
\r
67 public void BeginEdit ()
\r
69 _dataRow.BeginEdit ();
\r
72 public void CancelEdit ()
\r
75 if (this.Row == DataView._lastAdded)
\r
76 DataView.CompleteLastAdded (false);
\r
78 _dataRow.CancelEdit();
\r
81 public DataView CreateChildView (DataRelation relation)
\r
83 return DataView.CreateChildView (relation, _index);
\r
86 public DataView CreateChildView (string relationName)
\r
88 return CreateChildView (Row.Table.ChildRelations [relationName]);
\r
91 public void Delete ()
\r
93 DataView.Delete (_index);
\r
96 public void EndEdit ()
\r
99 if (this.Row == DataView._lastAdded)
\r
100 DataView.CompleteLastAdded(true);
\r
102 _dataRow.EndEdit();
\r
105 private void CheckAllowEdit ()
\r
107 if (!DataView.AllowEdit && (Row != DataView._lastAdded))
\r
108 throw new DataException ("Cannot edit on a DataSource where AllowEdit is false.");
\r
111 public DataView DataView {
\r
112 get { return _dataView; }
\r
115 public bool IsEdit {
\r
116 get { return _dataRow.HasVersion (DataRowVersion.Proposed); }
\r
119 // It becomes true when this instance is created by
\r
120 // DataView.AddNew(). If it is true, then the DataRow is
\r
121 // "Detached", and when this.EndEdit() is invoked, the row
\r
122 // will be added to the table.
\r
123 public bool IsNew {
\r
124 get { return Row == DataView._lastAdded; }
\r
127 public object this [string property] {
\r
129 DataColumn dc = _dataView.Table.Columns [property];
\r
131 throw new ArgumentException (
\r
132 property + " is neither a DataColumn nor a DataRelation for table " + _dataView.Table.TableName);
\r
133 return _dataRow [dc, GetActualRowVersion ()];
\r
137 DataColumn dc = _dataView.Table.Columns [property];
\r
139 throw new ArgumentException (
\r
140 property + " is neither a DataColumn nor a DataRelation for table " + _dataView.Table.TableName);
\r
141 _dataRow [dc] = value;
\r
145 public object this [int ndx] {
\r
147 DataColumn dc = _dataView.Table.Columns [ndx];
\r
149 throw new ArgumentException (
\r
150 ndx + " is neither a DataColumn nor a DataRelation for table " + _dataView.Table.TableName);
\r
151 return _dataRow [dc, GetActualRowVersion ()];
\r
155 DataColumn dc = _dataView.Table.Columns [ndx];
\r
157 throw new ArgumentException (
\r
158 ndx + " is neither a DataColumn nor a DataRelation for table " + _dataView.Table.TableName);
\r
159 _dataRow [dc] = value;
\r
163 private DataRowVersion GetActualRowVersion ()
\r
165 switch (_dataView.RowStateFilter) {
\r
166 case DataViewRowState.Added:
\r
167 return DataRowVersion.Proposed;
\r
168 case DataViewRowState.ModifiedOriginal:
\r
169 case DataViewRowState.Deleted:
\r
170 case DataViewRowState.Unchanged:
\r
171 case DataViewRowState.OriginalRows:
\r
172 return DataRowVersion.Original;
\r
173 case DataViewRowState.ModifiedCurrent:
\r
174 return DataRowVersion.Current;
\r
176 return DataRowVersion.Default;
\r
179 public DataRow Row {
\r
180 get { return _dataRow; }
\r
183 public DataRowVersion RowVersion {
\r
185 DataRowVersion version = DataView.GetRowVersion(_index);
\r
186 if (version != DataRowVersion.Original)
\r
187 version = DataRowVersion.Current;
\r
193 public override int GetHashCode ()
\r
195 return _dataRow.GetHashCode();
\r
198 internal int Index {
\r
199 get { return _index; }
\r
203 partial class DataRowView : ICustomTypeDescriptor {
\r
204 AttributeCollection ICustomTypeDescriptor.GetAttributes ()
\r
206 System.ComponentModel.AttributeCollection attributes;
\r
207 attributes = AttributeCollection.Empty;
\r
211 [MonoTODO ("Not implemented. Always returns String.Empty")]
\r
212 string ICustomTypeDescriptor.GetClassName ()
\r
214 return string.Empty;
\r
217 [MonoTODO ("Not implemented. Always returns null")]
\r
218 string ICustomTypeDescriptor.GetComponentName ()
\r
223 [MonoTODO ("Not implemented. Always returns null")]
\r
224 TypeConverter ICustomTypeDescriptor.GetConverter ()
\r
229 [MonoTODO ("Not implemented. Always returns null")]
\r
230 EventDescriptor ICustomTypeDescriptor.GetDefaultEvent ()
\r
235 [MonoTODO ("Not implemented. Always returns null")]
\r
236 PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty ()
\r
241 [MonoTODO ("Not implemented. Always returns null")]
\r
242 object ICustomTypeDescriptor.GetEditor (Type editorBaseType)
\r
247 [MonoTODO ("Not implemented. Always returns an empty collection")]
\r
248 EventDescriptorCollection ICustomTypeDescriptor.GetEvents ()
\r
250 return new EventDescriptorCollection (null);
\r
253 [MonoTODO ("Not implemented. Always returns an empty collection")]
\r
254 EventDescriptorCollection ICustomTypeDescriptor.GetEvents (Attribute [] attributes)
\r
256 return new EventDescriptorCollection (null);
\r
259 PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties ()
\r
261 if (DataView == null) {
\r
262 ITypedList typedList = (ITypedList) _dataView;
\r
263 return typedList.GetItemProperties (new PropertyDescriptor [0]);
\r
265 return DataView.Table.GetPropertyDescriptorCollection ();
\r
268 [MonoTODO ("It currently reports more descriptors than necessary")]
\r
269 PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties (Attribute [] attributes)
\r
271 PropertyDescriptorCollection descriptors;
\r
272 descriptors = ((ICustomTypeDescriptor) this).GetProperties ();
\r
273 // TODO: filter out descriptors which do not contain
\r
274 // any of those attributes
\r
275 // except, those descriptors
\r
276 // that contain DefaultMemeberAttribute
\r
277 return descriptors;
\r
281 object ICustomTypeDescriptor.GetPropertyOwner (PropertyDescriptor pd)
\r
287 partial class DataRowView : IDataErrorInfo {
\r
288 string IDataErrorInfo.Error {
\r
289 [MonoTODO ("Not implemented, always returns String.Empty")]
\r
290 get { return string.Empty; }
\r
293 string IDataErrorInfo.this [string colName] {
\r
294 [MonoTODO ("Not implemented, always returns String.Empty")]
\r
295 get { return string.Empty; }
\r
300 partial class DataRowView : INotifyPropertyChanged {
\r
301 public event PropertyChangedEventHandler PropertyChanged;
\r
303 void OnPropertyChanged (string propertyName)
\r
305 if (PropertyChanged != null) {
\r
306 PropertyChangedEventArgs args = new PropertyChangedEventArgs (propertyName);
\r
307 PropertyChanged (this, args);
\r