Facilitate the merge
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / DataGridViewRow.cs
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:
8 // 
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 // 
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.
19 // Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
20 //
21 // Author:
22 //      Pedro Martínez Juliá <pedromj@gmail.com>
23 //
24
25
26 #if NET_2_0
27
28 using System.ComponentModel;
29 using System.Drawing;
30 using System.Runtime.InteropServices;
31 using System.Collections;
32 using System.Collections.Generic;
33
34 namespace System.Windows.Forms
35 {
36         [TypeConverter (typeof (DataGridViewRowConverter))]
37         public class DataGridViewRow : DataGridViewBand
38         {
39                 private AccessibleObject accessibilityObject;
40                 private DataGridViewCellCollection cells;
41                 private ContextMenuStrip contextMenuStrip;
42                 private int dividerHeight;
43                 private string errorText;
44                 private DataGridViewRowHeaderCell headerCell;
45                 private int height;
46                 private int minimumHeight;
47                 private int explicit_height;
48
49                 public DataGridViewRow ()
50                 {
51                         cells = new DataGridViewCellCollection(this);
52                         minimumHeight = 3;
53                         height = -1;
54                         explicit_height = -1;
55                         headerCell = new DataGridViewRowHeaderCell();
56                         headerCell.SetOwningRow (this);
57                         accessibilityObject = new AccessibleObject ();
58                         SetState (DataGridViewElementStates.Visible);
59                 }
60
61                 [Browsable (false)]
62                 public AccessibleObject AccessibilityObject {
63                         get { return accessibilityObject; }
64                 }
65
66                 [Browsable (false)]
67                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
68                 public DataGridViewCellCollection Cells {
69                         get { return cells; }
70                 }
71
72                 [DefaultValue (null)]
73                 public override ContextMenuStrip ContextMenuStrip {
74                         get {
75                                 if (IsShared)
76                                         throw new InvalidOperationException ("Operation cannot be performed on a shared row.");
77                                         
78                                 return contextMenuStrip;
79                         }
80                         set {
81                                 if (contextMenuStrip != value) {
82                                         contextMenuStrip = value;
83                                         if (DataGridView != null) {
84                                                 DataGridView.OnRowContextMenuStripChanged(new DataGridViewRowEventArgs(this));
85                                         }
86                                 }
87                         }
88                 }
89
90                 [Browsable (false)]
91                 [EditorBrowsable (EditorBrowsableState.Advanced)]
92                 public object DataBoundItem {
93                         get {
94                                 if (base.DataGridView != null && DataGridView.DataManager != null) {
95                                         if (DataGridView.DataManager.Count > base.Index)
96                                                 return DataGridView.DataManager[base.Index];
97                                 }
98                                 return null;
99                         }
100                 }
101
102                 [Browsable (true)]
103                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
104                 [NotifyParentProperty (true)]
105                 public override DataGridViewCellStyle DefaultCellStyle {
106                         get { return base.DefaultCellStyle; }
107                         set {
108                                 if (DefaultCellStyle != value) {
109                                         base.DefaultCellStyle = value;
110                                         if (DataGridView != null) {
111                                                 DataGridView.OnRowDefaultCellStyleChanged(new DataGridViewRowEventArgs(this));
112                                         }
113                                 }
114                         }
115                 }
116
117                 [Browsable (false)]
118                 public override bool Displayed {
119                         get {
120                                 if (IsShared)
121                                         throw new InvalidOperationException ("Getting the Displayed property of a shared row is not a valid operation.");
122                                         
123                                 return base.Displayed;
124                         }
125                 }
126
127                 [DefaultValue (0)]
128                 [NotifyParentProperty (true)]
129                 public int DividerHeight {
130                         get { return dividerHeight; }
131                         set { dividerHeight = value; }
132                 }
133
134                 [DefaultValue ("")]
135                 [NotifyParentProperty (true)]
136                 public string ErrorText {
137                         get {
138                                 if (IsShared)
139                                         throw new InvalidOperationException ("Operation cannot be performed on a shared row.");
140                                         
141                                 return errorText == null ? string.Empty : errorText;
142                         }
143                         set {
144                                 if (errorText != value) {
145                                         errorText = value;
146                                         if (DataGridView != null) {
147                                                 DataGridView.OnRowErrorTextChanged(new DataGridViewRowEventArgs(this));
148                                         }
149                                 }
150                         }
151                 }
152
153                 [Browsable (false)]
154                 public override bool Frozen {
155                         get {
156                                 if (IsShared)
157                                         throw new InvalidOperationException ("Getting the Frozen property of a shared row is not a valid operation.");
158                                         
159                                 return base.Frozen;
160                         }
161                         set { base.Frozen = value; }
162                 }
163
164                 [Browsable (false)]
165                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
166                 public DataGridViewRowHeaderCell HeaderCell {
167                         get { return headerCell; }
168                         set {
169                                 if (headerCell != value) {
170                                         headerCell = value;
171                                         headerCell.SetOwningRow (this);
172                                         
173                                         if (DataGridView != null) {
174                                                 headerCell.SetDataGridView (DataGridView);
175                                                 DataGridView.OnRowHeaderCellChanged(new DataGridViewRowEventArgs(this));
176                                         }
177                                 }
178                         }
179                 }
180
181                 [DefaultValue (22)]
182                 [NotifyParentProperty (true)]
183                 public int Height {
184                         get {
185                                 if (height < 0) {
186                                         if (DefaultCellStyle != null && DefaultCellStyle.Font != null) {
187                                                 return DefaultCellStyle.Font.Height + 9;
188                                         }
189                                         if (Index >= 0 && InheritedStyle != null && InheritedStyle.Font != null) {
190                                                 return InheritedStyle.Font.Height + 9;
191                                         }
192                                         return System.Windows.Forms.Control.DefaultFont.Height + 9;
193                                 }
194                                 return height;
195                         }
196                         set {
197                                 explicit_height = value;
198                                 
199                                 if (height != value) {
200                                         if (value < minimumHeight) {
201                                                 throw new ArgumentOutOfRangeException("Height can't be less than MinimumHeight.");
202                                         }
203                                         height = value;
204                                         if (DataGridView != null) {
205                                                 DataGridView.Invalidate ();
206                                                 DataGridView.OnRowHeightChanged(new DataGridViewRowEventArgs(this));
207                                         }
208                                 }
209                         }
210                 }
211
212                 public override DataGridViewCellStyle InheritedStyle {
213                         get {
214                                 if (Index == -1)
215                                         throw new InvalidOperationException ("Getting the InheritedStyle property of a shared row is not a valid operation.");
216                                         
217                                 if (DataGridView == null) {
218                                         return DefaultCellStyle;
219                                 }
220                                 else {
221                                         if (DefaultCellStyle == null) {
222                                                 return DataGridView.DefaultCellStyle;
223                                         }
224                                         else {
225                                                 DataGridViewCellStyle style = (DataGridViewCellStyle) DefaultCellStyle.Clone();
226                                                 /////// Combination with dataGridView.DefaultCellStyle
227                                                 return style;
228                                         }
229                                 }
230                         }
231                 }
232
233                 [Browsable (false)]
234                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
235                 public bool IsNewRow {
236                         get {
237                                 if (DataGridView != null && DataGridView.Rows[DataGridView.Rows.Count - 1] == this && DataGridView.NewRowIndex == Index) {
238                                         return true;
239                                 }
240                                 return false;
241                         }
242                 }
243
244                 internal bool IsShared {
245                         get {
246                                 return Index == -1 && DataGridView != null;
247                         }
248                 }
249
250                 [Browsable (false)]
251                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
252                 public int MinimumHeight {
253                         get { return minimumHeight; }
254                         set {
255                                 if (minimumHeight != value) {
256                                         if (value < 2 || value > Int32.MaxValue) {
257                                                 throw new ArgumentOutOfRangeException("MinimumHeight should be between 2 and Int32.MaxValue.");
258                                         }
259                                         minimumHeight = value;
260                                         if (DataGridView != null) {
261                                                 DataGridView.OnRowMinimumHeightChanged(new DataGridViewRowEventArgs(this));
262                                         }
263                                 }
264                         }
265                 }
266
267                 [Browsable (true)]
268                 [DefaultValue (false)]
269                 [NotifyParentProperty (true)]
270                 public override bool ReadOnly {
271                         get {
272                                 if (IsShared)
273                                         throw new InvalidOperationException ("Getting the ReadOnly property of a shared row is not a valid operation.");
274                                         
275                                 if (DataGridView != null && DataGridView.ReadOnly)
276                                         return true;
277                                         
278                                 return base.ReadOnly;
279                         }
280                         set { base.ReadOnly = value; }
281                 }
282
283                 [NotifyParentProperty (true)]
284                 public override DataGridViewTriState Resizable {
285                         get {
286                                 if (IsShared)
287                                         throw new InvalidOperationException ("Getting the Resizable property of a shared row is not a valid operation.");
288                                         
289                                 return base.Resizable;
290                         }
291                         set { base.Resizable = value; }
292                 }
293
294                 public override bool Selected {
295                         get {
296                                 if (IsShared)
297                                         throw new InvalidOperationException ("Getting the Selected property of a shared row is not a valid operation.");
298                                         
299                                 return base.Selected;
300                         }
301                         set {
302                                 if (Index == -1) {
303                                         throw new InvalidOperationException("The row is a shared row.");
304                                 }
305                                 if (DataGridView == null) {
306                                         throw new InvalidOperationException("The row has not been added to a DataGridView control.");
307                                 }
308                                 base.Selected = value;
309                         }
310                 }
311
312                 public override DataGridViewElementStates State {
313                         get {
314                                 if (IsShared)
315                                         throw new InvalidOperationException ("Getting the State property of a shared row is not a valid operation.");
316                                         
317                                 return base.State;
318                         }
319                 }
320
321                 [Browsable (false)]
322                 public override bool Visible {
323                         get {
324                                 if (IsShared)
325                                         throw new InvalidOperationException ("Getting the Visible property of a shared row is not a valid operation.");
326                                         
327                                 return base.Visible;
328                         }
329                         set {
330                                 if (IsNewRow && value == false) {
331                                         throw new InvalidOperationException("Cant make invisible a new row.");
332                                 }
333                                 if (!value && DataGridView != null && DataGridView.DataManager != null && 
334                                     DataGridView.DataManager.Position == Index)
335                                         throw new InvalidOperationException("Row associated with the currency manager's position cannot be made invisible.");
336
337                                 base.Visible = value;
338                                 if (DataGridView != null)
339                                         DataGridView.Invalidate ();
340                         }
341                 }
342
343                 [EditorBrowsable (EditorBrowsableState.Advanced)]
344                 public virtual DataGridViewAdvancedBorderStyle AdjustRowHeaderBorderStyle (DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStyleInput, DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStylePlaceholder, bool singleVerticalBorderAdded, bool singleHorizontalBorderAdded, bool isFirstDisplayedRow, bool isLastVisibleRow)
345                 {
346                         throw new NotImplementedException();
347                 }
348
349                 public override object Clone ()
350                 {
351                         DataGridViewRow row = (DataGridViewRow)MemberwiseClone ();
352
353                         row.HeaderCell = (DataGridViewRowHeaderCell)HeaderCell.Clone ();
354                         row.SetIndex (-1);
355                         
356                         row.cells = new DataGridViewCellCollection (row);
357                         
358                         foreach (DataGridViewCell cell in cells)
359                                 row.cells.Add (cell.Clone () as DataGridViewCell);
360
361                         row.SetDataGridView (null);
362
363                         return row;
364                 }
365
366                 public void CreateCells (DataGridView dataGridView)
367                 {
368                         if (dataGridView == null) {
369                                 throw new ArgumentNullException("DataGridView is null.");
370                         }
371                         if (dataGridView.Rows.Contains(this)) {
372                                 throw new InvalidOperationException("The row already exists in the DataGridView.");
373                         }
374                         DataGridViewCellCollection newCellCollection = new DataGridViewCellCollection(this);
375                         foreach (DataGridViewColumn column in dataGridView.Columns) {
376                                 if (column.CellTemplate == null) {
377                                         throw new InvalidOperationException("Cell template not set in column: " + column.Index.ToString() + ".");
378                                 }
379                                 newCellCollection.Add((DataGridViewCell) column.CellTemplate.Clone());
380                         }
381                         cells = newCellCollection;
382                 }
383
384                 public void CreateCells (DataGridView dataGridView, params object[] values)
385                 {
386                         if (values == null) {
387                                 throw new ArgumentNullException("values is null");
388                         }
389                         CreateCells(dataGridView);
390                         for (int i = 0; i < values.Length; i++) {
391                                 cells[i].Value = values[i];
392                         }
393                 }
394
395                 public ContextMenuStrip GetContextMenuStrip (int rowIndex)
396                 {
397                         if (rowIndex == -1) {
398                                 throw new InvalidOperationException("rowIndex is -1");
399                         }
400                         if (rowIndex < 0 || rowIndex >= DataGridView.Rows.Count) {
401                                 throw new ArgumentOutOfRangeException("rowIndex is out of range");
402                         }
403
404                         return null; // XXX
405                 }
406
407                 public string GetErrorText (int rowIndex)
408                 {
409                         return string.Empty;
410                 }
411
412                 public virtual int GetPreferredHeight (int rowIndex, DataGridViewAutoSizeRowMode autoSizeRowMode, bool fixedWidth)
413                 {
414                         DataGridViewRow row;
415                         
416                         if (DataGridView != null)
417                                 row = DataGridView.Rows.SharedRow (rowIndex);
418                         else
419                                 row = this;
420
421                         int height = 0;
422
423                         if (autoSizeRowMode == DataGridViewAutoSizeRowMode.AllCells || autoSizeRowMode == DataGridViewAutoSizeRowMode.RowHeader)
424                                 height = Math.Max (height, row.HeaderCell.PreferredSize.Height);
425
426                         if (autoSizeRowMode == DataGridViewAutoSizeRowMode.AllCells || autoSizeRowMode == DataGridViewAutoSizeRowMode.AllCellsExceptHeader)
427                                 foreach (DataGridViewCell cell in row.Cells)
428                                         height = Math.Max (height, cell.PreferredSize.Height);
429                         
430                         return height;
431                 }
432
433                 [EditorBrowsable (EditorBrowsableState.Advanced)]
434                 public virtual DataGridViewElementStates GetState (int rowIndex)
435                 {
436                         DataGridViewElementStates state = DataGridViewElementStates.None;
437                         
438                         if (rowIndex == -1) {
439                                 state |= DataGridViewElementStates.Displayed;
440                                 
441                                 if (DataGridView.ReadOnly)
442                                         state |= DataGridViewElementStates.ReadOnly;
443                                 if (DataGridView.AllowUserToResizeRows)
444                                         state |= DataGridViewElementStates.Resizable;
445                                 if (DataGridView.Visible)
446                                         state |= DataGridViewElementStates.Visible;
447                         
448                                 return state;
449                         }
450                         
451                         DataGridViewRow row = DataGridView.Rows[rowIndex];
452
453                         if (row.Displayed)
454                                 state |= DataGridViewElementStates.Displayed;
455                         if (row.Frozen)
456                                 state |= DataGridViewElementStates.Frozen;
457                         if (row.ReadOnly)
458                                 state |= DataGridViewElementStates.ReadOnly;
459                         if (row.Resizable == DataGridViewTriState.True || (row.Resizable == DataGridViewTriState.NotSet && DataGridView.AllowUserToResizeRows))
460                                 state |= DataGridViewElementStates.Resizable;
461                         if (row.Resizable == DataGridViewTriState.True)
462                                 state |= DataGridViewElementStates.ResizableSet;
463                         if (row.Selected)
464                                 state |= DataGridViewElementStates.Selected;
465                         if (row.Visible)
466                                 state |= DataGridViewElementStates.Visible;
467                                 
468                         return state;
469                 }
470
471                 public bool SetValues (params object[] values)
472                 {
473                         if (values == null) {
474                                 throw new ArgumentNullException("vues is null");
475                         }
476                         if (DataGridView != null && DataGridView.VirtualMode) {
477                                 throw new InvalidOperationException("DataGridView is operating in virtual mode");
478                         }
479                         /////// COLUMNAS //////////
480                         for (int i = 0; i < values.Length; i++) {
481                                 DataGridViewCell cell;
482                                 if (cells.Count > i) {
483                                         cell = cells [i];
484                                 } else {
485                                         cell = new DataGridViewTextBoxCell ();
486                                         cells.Add (cell);
487                                 }
488                                 cell.Value = values[i];
489                         }
490                         
491                         // XXX
492                         return true;
493                 }
494
495                 public override string ToString ()
496                 {
497                         return this.GetType().Name + ", Band Index: " + base.Index.ToString();
498                 }
499
500                 protected virtual AccessibleObject CreateAccessibilityInstance ()
501                 {
502                         return new DataGridViewRowAccessibleObject(this);
503                 }
504
505                 [EditorBrowsable (EditorBrowsableState.Advanced)]
506                 protected virtual DataGridViewCellCollection CreateCellsInstance ()
507                 {
508                         cells = new DataGridViewCellCollection(this);
509                         return cells;
510                 }
511
512                 [EditorBrowsable (EditorBrowsableState.Advanced)]
513                 protected internal virtual void DrawFocus (Graphics graphics, Rectangle clipBounds, Rectangle bounds, int rowIndex, DataGridViewElementStates rowState, DataGridViewCellStyle cellStyle, bool cellsPaintSelectionBackground)
514                 {
515                 }
516
517                 protected internal virtual void Paint (Graphics graphics, Rectangle clipBounds, Rectangle rowBounds, int rowIndex, DataGridViewElementStates rowState, bool isFirstDisplayedRow, bool isLastVisibleRow)
518                 {
519                         DataGridViewCellStyle style;
520                         
521                         if (Index == -1)
522                                 style = DataGridView.RowsDefaultCellStyle;
523                         else
524                                 style = InheritedStyle;
525                                 
526                         DataGridViewRowPrePaintEventArgs pre = new DataGridViewRowPrePaintEventArgs (DataGridView, graphics, clipBounds, rowBounds, rowIndex, rowState, string.Empty, style, isFirstDisplayedRow, isLastVisibleRow);
527                         pre.PaintParts = DataGridViewPaintParts.All;
528
529                         DataGridView.OnRowPrePaint (pre);
530
531                         // The user has elected for us to not do anything
532                         if (pre.Handled)
533                                 return;
534
535                         if (DataGridView.RowHeadersVisible)
536                                 PaintHeader (graphics, pre.ClipBounds, rowBounds, rowIndex, rowState, isFirstDisplayedRow, isLastVisibleRow, pre.PaintParts);
537                         
538                         PaintCells (graphics, pre.ClipBounds, rowBounds, rowIndex, rowState, isFirstDisplayedRow, isLastVisibleRow, pre.PaintParts);
539
540                         DataGridViewRowPostPaintEventArgs post = new DataGridViewRowPostPaintEventArgs (DataGridView, graphics, pre.ClipBounds, rowBounds, rowIndex, rowState, pre.ErrorText, style, isFirstDisplayedRow, isLastVisibleRow);
541                         DataGridView.OnRowPostPaint (post);
542                 }
543
544                 [EditorBrowsable (EditorBrowsableState.Advanced)]
545                 protected internal virtual void PaintCells (Graphics graphics, Rectangle clipBounds, Rectangle rowBounds, int rowIndex, DataGridViewElementStates rowState, bool isFirstDisplayedRow, bool isLastVisibleRow, DataGridViewPaintParts paintParts)
546                 {
547                         List<DataGridViewColumn> sortedColumns = DataGridView.Columns.ColumnDisplayIndexSortedArrayList;
548                         
549                         Rectangle bounds = rowBounds;
550                         
551                         // If row headers are visible, adjust our starting point
552                         if (DataGridView.RowHeadersVisible) {
553                                 bounds.X += DataGridView.RowHeadersWidth;
554                                 bounds.Width -= DataGridView.RowHeadersWidth;
555                         }
556                         
557                         for (int i = DataGridView.first_col_index; i < sortedColumns.Count; i++) {
558                                 DataGridViewColumn col = sortedColumns[i];
559                                 
560                                 if (!col.Visible)
561                                         continue;
562                                         
563                                 if (!col.Displayed)
564                                         break;
565                                         
566                                 bounds.Width = col.Width;
567                                 DataGridViewCell cell = Cells[col.Index];
568                                 
569                                 if ((paintParts & DataGridViewPaintParts.Background) == DataGridViewPaintParts.Background)
570                                         graphics.FillRectangle (Brushes.White, bounds);
571                                 
572                                 DataGridViewCellStyle style;
573
574                                 if (cell.RowIndex == -1)
575                                         style = DefaultCellStyle;
576                                 else
577                                         style = cell.InheritedStyle;
578
579                                 object value;
580                                 object formattedValue;
581                                 string errorText;
582                                 DataGridViewElementStates cellState;
583                                 
584                                 if (cell.RowIndex == -1) {
585                                         // TODO: Look up value if databound.
586                                         value = null;
587                                         formattedValue = null;
588                                         errorText = null;
589                                         cellState = cell.State;
590                                 } else {
591                                         value = cell.Value;
592                                         formattedValue = cell.FormattedValue;
593                                         errorText = cell.ErrorText;
594                                         cellState = cell.InheritedState;
595                                 }
596
597                                 DataGridViewAdvancedBorderStyle intermediateBorderStyle = (DataGridViewAdvancedBorderStyle)((ICloneable)DataGridView.AdvancedCellBorderStyle).Clone ();
598                                 DataGridViewAdvancedBorderStyle borderStyle = cell.AdjustCellBorderStyle (DataGridView.AdvancedCellBorderStyle, intermediateBorderStyle, true, true, cell.ColumnIndex == 0, cell.RowIndex == 0);
599                                 DataGridView.OnCellFormattingInternal (new DataGridViewCellFormattingEventArgs (cell.ColumnIndex, cell.RowIndex, value, cell.FormattedValueType, style));
600
601
602                                 cell.PaintWork (graphics, clipBounds, bounds, rowIndex, cellState, style, borderStyle, paintParts);
603                                 bounds.X += bounds.Width;
604                         }
605                 }
606
607                 [EditorBrowsable (EditorBrowsableState.Advanced)]
608                 protected internal virtual void PaintHeader (Graphics graphics, Rectangle clipBounds, Rectangle rowBounds, int rowIndex, DataGridViewElementStates rowState, bool isFirstDisplayedRow, bool isLastVisibleRow, DataGridViewPaintParts paintParts)
609                 {
610                         rowBounds.Width = DataGridView.RowHeadersWidth;
611                         graphics.FillRectangle (Brushes.White, rowBounds);
612         
613                         HeaderCell.PaintWork (graphics, clipBounds, rowBounds, rowIndex, rowState, HeaderCell.InheritedStyle, DataGridView.AdvancedRowHeadersBorderStyle, paintParts);
614                 }
615
616                 internal override void SetDataGridView (DataGridView dataGridView)
617                 {
618                         base.SetDataGridView(dataGridView);
619                         headerCell.SetDataGridView(dataGridView);
620                         foreach (DataGridViewCell cell in cells)
621                                 cell.SetDataGridView (dataGridView);
622                 }
623
624                 internal override void SetState (DataGridViewElementStates state)
625                 {
626                         if (State != state) {
627                                 base.SetState(state);
628                                 if (DataGridView != null) {
629                                         DataGridView.OnRowStateChanged(this.Index, new DataGridViewRowStateChangedEventArgs(this, state));
630                                 }
631                         }
632                 }
633                 
634                 // Set the row's height without overwriting the explicit_height, so we
635                 // can go back to the user's requested height when they turn off AutoSize
636                 internal void SetAutoSizeHeight (int height)
637                 {
638                         this.height = height;
639                         
640                         if (DataGridView != null) {
641                                 DataGridView.Invalidate ();
642                                 DataGridView.OnRowHeightChanged (new DataGridViewRowEventArgs (this));
643                         }
644                 }
645
646                 // If the user sets AutoSizeRowMode to None, reset every row to its explicit height
647                 internal void ResetToExplicitHeight ()
648                 {
649                         this.height = explicit_height;
650
651                         if (DataGridView != null)
652                                 DataGridView.OnRowHeightChanged (new DataGridViewRowEventArgs (this));
653                 }
654                 
655                 [ComVisibleAttribute(true)]
656                 protected class DataGridViewRowAccessibleObject : AccessibleObject {
657
658                         private DataGridViewRow dataGridViewRow;
659
660                         public DataGridViewRowAccessibleObject ()
661                         {
662                         }
663
664                         public DataGridViewRowAccessibleObject (DataGridViewRow owner)
665                         {
666                                 this.dataGridViewRow = owner;
667                         }
668
669                         public override Rectangle Bounds {
670                                 get { throw new NotImplementedException(); }
671                         }
672
673                         public override string Name {
674                                 get { return "Index: " + dataGridViewRow.Index.ToString(); }
675                         }
676
677                         public DataGridViewRow Owner {
678                                 get { return dataGridViewRow; }
679                                 set { dataGridViewRow = value; }
680                         }
681
682                         public override AccessibleObject Parent {
683                                 get { return dataGridViewRow.AccessibilityObject; }
684                         }
685
686                         public override AccessibleRole Role {
687                                 get { return AccessibleRole.Row; }
688                         }
689
690                         public override AccessibleStates State {
691                                 get {
692                                         if (dataGridViewRow.Selected) {
693                                                 return AccessibleStates.Selected;
694                                         }
695                                         else {
696                                                 return AccessibleStates.Focused;
697                                         }
698                                 }
699                         }
700
701                         public override string Value {
702                                 get {
703                                         if (dataGridViewRow.Cells.Count == 0) {
704                                                 return "(Create New)";
705                                         }
706                                         string result = "";
707                                         foreach (DataGridViewCell cell in dataGridViewRow.Cells) {
708                                                 result += cell.AccessibilityObject.Value;
709                                         }
710                                         return result;
711                                 }
712                         }
713
714                         public override AccessibleObject GetChild (int index) {
715                                 throw new NotImplementedException();
716                         }
717
718                         public override int GetChildCount () {
719                                 throw new NotImplementedException();
720                         }
721
722                         public override AccessibleObject GetFocused () {
723                                 return null;
724                         }
725
726                         public override AccessibleObject GetSelected () {
727                                 return null;
728                         }
729
730                         public override AccessibleObject Navigate (AccessibleNavigation navigationDirection) {
731                                 switch (navigationDirection) {
732                                         case AccessibleNavigation.Right:
733                                                 break;
734                                         case AccessibleNavigation.Left:
735                                                 break;
736                                         case AccessibleNavigation.Next:
737                                                 break;
738                                         case AccessibleNavigation.Previous:
739                                                 break;
740                                         case AccessibleNavigation.Up:
741                                                 break;
742                                         case AccessibleNavigation.Down:
743                                                 break;
744                                         default:
745                                                 return null;
746                                 }
747                                 return null;
748                         }
749
750                         public override void Select (AccessibleSelection flags) {
751                                 switch (flags) {
752                                         case AccessibleSelection.TakeFocus:
753                                                 dataGridViewRow.DataGridView.Focus();
754                                                 break;
755                                         case AccessibleSelection.TakeSelection:
756                                                 //dataGridViewRow.Focus();
757                                                 break;
758                                         case AccessibleSelection.AddSelection:
759                                                 dataGridViewRow.DataGridView.SelectedRows.InternalAdd(dataGridViewRow);
760                                                 break;
761                                         case AccessibleSelection.RemoveSelection:
762                                                 dataGridViewRow.DataGridView.SelectedRows.InternalRemove(dataGridViewRow);
763                                                 break;
764                                 }
765                         }
766                 }
767         }
768         
769         internal class DataGridViewRowConverter : TypeConverter
770         {
771         }
772 }
773
774 #endif