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