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