2009-06-12 Bill Holmes <billholmes54@gmail.com>
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / DataGridViewTest.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 //
20 // Copyright (c) 2005, 2006, 2007 Novell, Inc. (http://www.novell.com)
21 //
22 // Author:
23 //      Pedro Martínez Juliá <pedromj@gmail.com>
24 //      Daniel Nauck    (dna(at)mono-project(dot)de)
25 //      Ivan N. Zlatev  <contact@i-nz.net>
26
27
28 #if NET_2_0
29
30 using System;
31 using System.Data;
32 using System.Drawing;
33 using System.Collections;
34 using System.Collections.Generic;
35 using System.ComponentModel;
36 using System.Diagnostics;
37 using System.IO;
38 using System.Text;
39 using System.Windows.Forms;
40
41 using NUnit.Framework;
42
43 namespace MonoTests.System.Windows.Forms
44 {
45         [TestFixture]
46         public class DataGridViewTest : TestHelper
47         {
48                 private DataGridView grid = null;
49
50                 [SetUp]
51                 protected override void SetUp()
52                 {
53                         grid = new DataGridView();
54                         base.SetUp ();
55                 }
56
57                 [TearDown]
58                 protected override void TearDown ()
59                 {
60                         grid.Dispose ();
61                         base.TearDown ();
62                 }
63
64                 [Test]
65                 [ExpectedException (typeof (InvalidOperationException), "Generating Clipboard content is not supported when the ClipboardCopyMode property is Disable.")]
66                 public void GetClipboardContentsDisabled ()
67                 {
68                         using (DataGridView dgv = new DataGridView ()) {
69                                 dgv.ClipboardCopyMode = DataGridViewClipboardCopyMode.Disable;
70                                 object o = dgv.GetClipboardContent ();
71                         }
72                 }
73
74                 private class ExposeProtectedProperties : DataGridView
75                 {
76                         public new Padding DefaultPadding { get { return base.DefaultPadding; } }
77                         public new Size DefaultSize { get { return base.DefaultSize; } }
78                         public new bool IsDoubleBuffered { get { return base.DoubleBuffered; } }
79
80                         public ControlStyles GetControlStyles ()
81                         {
82                                 ControlStyles retval = (ControlStyles)0;
83
84                                 foreach (ControlStyles cs in Enum.GetValues (typeof (ControlStyles)))
85                                         if (this.GetStyle (cs) == true)
86                                                 retval |= cs;
87
88                                 return retval;
89                         }
90                         
91                         public bool PublicIsInputKey (Keys keyData)
92                         {
93                                 return base.IsInputKey (keyData);
94                         }
95                         
96                         public bool PublicIsInputChar (char charCode)
97                         {
98                                 return base.IsInputChar (charCode);
99                         }
100                 }
101
102 #region GenerateClipboardTest
103                 public static void GenerateClipboardTest ()
104                 {
105                         GenerateClipboardTest (false);
106                         GenerateClipboardTest (true);
107                 }
108
109                 public static string GenerateClipboardTest (bool headers)
110                 {
111                         StringBuilder result = new StringBuilder ();
112
113                         int tab = 0;
114                         string classname = headers ? "DataGridViewClipboardHeaderTest" : "DataGridViewClipboardTest";
115
116                         append (result, tab, "//");
117                         append (result, tab, "// Copyright (c) 2007 Novell, Inc. (http://www.novell.com)");
118                         append (result, tab, "//");
119                         append (result, tab, "// Author:");
120                         append (result, tab, "//        DataGridViewTest.GenerateClipboardTest ({0});", headers.ToString ().ToLower ());
121                         append (result, tab, "//");
122                         append (result, tab, "#if NET_2_0");
123                         append (result, tab, "using NUnit.Framework;");
124                         append (result, tab, "using System;");
125                         append (result, tab, "using System.Drawing;");
126                         append (result, tab, "using System.Windows.Forms;");
127                         append (result, tab, "using System.ComponentModel;");
128                         append (result, tab, "using System.Collections;");
129                         append (result, tab, "using System.Text;");
130                         append (result, tab, "using System.Collections.Generic;");
131                         append (result, tab, "using System.Diagnostics;");
132                         append (result, tab, "using System.IO;");
133                         append (result, tab, "namespace MonoTests.System.Windows.Forms {"); tab++;
134                         append (result, tab, "[TestFixture]");
135                         append (result, tab, "public class {0} {{", classname); tab++;
136                         append (result, tab, "[Test]");
137                         append (result, tab, "public void Test () {"); tab++;
138
139
140                         append (result, tab, "DataObject data;");
141                         append (result, tab, "DataGridViewRowHeaderTest.DataGridViewRowHeaderClipboardCell row_header_cell;");
142                         append (result, tab, "DataGridViewColumnHeaderTest.DataGridViewColumnHeaderClipboardCell col_header_cell;");
143                         //append (result, tab, "string csv = null, html = null, utext = null, text = null;");
144                         append (result, tab, "string code = null;");
145
146                         int counter;
147
148                         List<List<int>> selected_bands = new List<List<int>> ();
149                         List<List<CellSelection>> selected_cells = new List<List<CellSelection>> ();
150
151                         selected_bands.Add (new List<int> ());
152                         selected_bands.Add (new List<int> (new int [] { 0 }));
153                         selected_bands.Add (new List<int> (new int [] { 2 }));
154                         selected_bands.Add (new List<int> (new int [] { 1, 2 }));
155                         selected_bands.Add (new List<int> (new int [] { 1, 3 }));
156
157                         selected_cells.Add (new List<CellSelection> ());
158                         selected_cells.Add (new List<CellSelection> (new CellSelection [] { new CellSelection (0, 0, true) }));
159                         selected_cells.Add (new List<CellSelection> (new CellSelection [] { new CellSelection (2, 2, false) }));
160                         selected_cells.Add (new List<CellSelection> (new CellSelection [] { new CellSelection (0, 0, false), new CellSelection (2, 2, true) }));
161
162                         foreach (DataGridViewClipboardCopyMode copymode in Enum.GetValues (typeof (DataGridViewClipboardCopyMode))) {
163                                 if (copymode == DataGridViewClipboardCopyMode.Disable)
164                                         continue;
165
166                                 counter = 0;
167                                 foreach (DataGridViewSelectionMode selectionmode in Enum.GetValues (typeof (DataGridViewSelectionMode))) {
168                                         bool is_row_selectable, is_col_selectable, is_cell_selectable;
169
170                                         is_row_selectable = selectionmode == DataGridViewSelectionMode.RowHeaderSelect || selectionmode == DataGridViewSelectionMode.FullRowSelect;
171                                         is_col_selectable = selectionmode == DataGridViewSelectionMode.ColumnHeaderSelect || selectionmode == DataGridViewSelectionMode.FullColumnSelect;
172                                         is_cell_selectable = selectionmode == DataGridViewSelectionMode.CellSelect || selectionmode == DataGridViewSelectionMode.ColumnHeaderSelect || selectionmode == DataGridViewSelectionMode.RowHeaderSelect;
173
174                                         foreach (List<int> cols in selected_bands) {
175                                                 if (!is_col_selectable && cols.Count > 0)
176                                                         continue;
177
178                                                 foreach (List<int> rows in selected_bands) {
179                                                         if (!is_row_selectable && rows.Count > 0)
180                                                                 continue;
181
182                                                         foreach (List<CellSelection> cells in selected_cells) {
183                                                                 if (!is_cell_selectable && cells.Count > 0)
184                                                                         continue;
185
186                                                                 using (DataGridView dgv = DataGridViewCommon.CreateAndFillForClipboard ()) {
187
188                                                                         dgv.SelectionMode = selectionmode;
189                                                                         dgv.ClipboardCopyMode = copymode;
190                                                                         bool any_selected = false;
191                                                                         if (is_col_selectable && cols.Count > 0) {
192                                                                                 foreach (int c in cols) {
193                                                                                         dgv.Columns [c].Selected = true;
194                                                                                         any_selected = true;
195                                                                                 }
196                                                                         }
197                                                                         if (is_row_selectable && rows.Count > 0) {
198                                                                                 foreach (int r in rows) {
199                                                                                         dgv.Rows [r].Selected = true;
200                                                                                         any_selected = true;
201                                                                                 }
202                                                                         }
203                                                                         if (is_cell_selectable && cells.Count > 0) {
204                                                                                 foreach (CellSelection selection in cells) {
205                                                                                         DataGridViewCell cell = dgv.Rows [selection.Row].Cells [selection.Col];
206                                                                                         if (cell.Selected != selection.Selected) {
207                                                                                                 cell.Selected = selection.Selected;
208                                                                                                 any_selected = true;
209                                                                                         }
210                                                                                 }
211                                                                         }
212
213                                                                         if (any_selected == false && !(cols.Count == 0 && rows.Count == 0 && cells.Count == 0)) {
214                                                                                 continue;
215                                                                         }
216
217                                                                         generate_case (result, dgv, copymode.ToString () + "#" + (counter++).ToString (), headers);
218                                                                 }
219                                                         }
220                                                 }
221                                         }
222                                 }
223                         }
224
225                         append (result, --tab, "}");
226                         append (result, --tab, "}");
227                         append (result, --tab, "}");
228                         append (result, tab, "#endif"); ;
229
230                         throw new NotImplementedException ("Where am I?");
231                         // Uncomment the following line, change the path, and comment out the exception.
232                         //File.WriteAllText (@"Z:\mono\head\mcs\class\SWF\Test\System.Windows.Forms\" + classname + ".cs", result.ToString ());
233
234                         return string.Empty;
235                 }
236                 
237                 private static string tabs (int t) { return new string ('\t', t); }
238                 private static void append (StringBuilder result, int tab, string text) { result.Append (tabs (tab) + text + "\n"); }
239                 private static void append (StringBuilder result, int tab, string text, params object [] args) { result.Append (tabs (tab) + string.Format (text, args) + "\n"); }
240                 private static string cs_encode (string literal, string newline) {
241                         bool has_newlines = literal.Contains ("\r\n");
242                         bool format_string = has_newlines;
243
244                         literal = literal.Replace ("\\", "\\\\");
245                         literal = literal.Replace ("\"", "\\\"");
246                         literal = literal.Replace ("\t", "\\t");
247                         
248                         if (has_newlines) {
249                                 if (newline == @"""\r\n""") {
250                                         literal = literal.Replace ("\r\n", @"\r\n");
251                                         format_string = false;
252                                 } else {
253                                         literal = literal.Replace ("\r\n", "{0}");
254                                 }
255                         }
256
257                         literal = "\"" + literal + "\"";
258
259                         if (format_string) {
260                                 return "string.Format (" + literal/*.Replace ("{", "{{").Replace ("}", "}}")*/ + ", " + newline + ")";
261                         } else {
262                                 return literal;
263                         }
264                 }
265                 
266                 private static string cs_encode (string literal) {
267                         return cs_encode (literal, "Environment.NewLine");
268                 }
269                 
270                 private class CellSelection {
271                         public bool Selected;
272                         public int Row;
273                         public int Col;
274                         public CellSelection (int Row, int Col, bool Selected) {
275                                 this.Selected = Selected;
276                                 this.Row = Row;
277                                 this.Col = Col;
278                         }
279                 }
280                 
281                 static private void generate_case (StringBuilder result, DataGridView dgv, string message, bool headers)
282                 {
283                         Console.WriteLine (message + ", current length: " + result.Length.ToString ());
284                         Debug.WriteLine (message + ", current length: " + result.Length.ToString ());
285                         
286                         if (headers) {
287                                 if (dgv.SelectionMode != DataGridViewSelectionMode.CellSelect)
288                                         return;
289                                 if (dgv.ClipboardCopyMode != DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText)
290                                         return;
291                         }
292                         
293                         int tab = 3;
294                         DataObject data;
295                         string csv = null, html = null, utext = null, text = null;
296                         string code = null;
297                         DataGridViewRowHeaderTest.DataGridViewRowHeaderClipboardCell row_header_cell;
298                         DataGridViewColumnHeaderTest.DataGridViewColumnHeaderClipboardCell col_header_cell;
299                         int counter = 0;
300                         
301                         append (result, tab, "using (DataGridView dgv = DataGridViewCommon.CreateAndFillForClipboard ()) {");
302                         tab++;
303                         
304                         append (result, tab, "dgv.SelectionMode = DataGridViewSelectionMode.{0};", dgv.SelectionMode.ToString ());
305                         append (result, tab, "dgv.ClipboardCopyMode = DataGridViewClipboardCopyMode.{0};", dgv.ClipboardCopyMode.ToString ());
306                         
307                         switch (dgv.SelectionMode) {
308                         case DataGridViewSelectionMode.FullRowSelect:
309                                 foreach (DataGridViewRow row in dgv.Rows) {
310                                         if (row.Selected) {
311                                                 append (result, tab, "dgv.Rows [{0}].Selected = true;", row.Index);
312                                         }
313                                 }
314                                 break;
315                         case DataGridViewSelectionMode.FullColumnSelect:
316                                 foreach (DataGridViewColumn col in dgv.Columns) {
317                                         if (col.Selected) {
318                                                 append (result, tab, "dgv.Columns [{0}].Selected = true;", col.Index);
319                                         }
320                                 }
321                                 break;
322                         case DataGridViewSelectionMode.ColumnHeaderSelect:
323                         case DataGridViewSelectionMode.RowHeaderSelect:
324                         case DataGridViewSelectionMode.CellSelect:
325                                 if (dgv.SelectionMode == DataGridViewSelectionMode.RowHeaderSelect) {
326                                         foreach (DataGridViewRow row in dgv.Rows) {
327                                                 if (row.Selected) {
328                                                         append (result, tab, "dgv.Rows [{0}].Selected = true;", row.Index);
329                                                 }
330                                         }
331                                 }
332                                 if (dgv.SelectionMode == DataGridViewSelectionMode.ColumnHeaderSelect) {
333                                         foreach (DataGridViewColumn col in dgv.Columns) {
334                                                 if (col.Selected) {
335                                                         append (result, tab, "dgv.Columns [{0}].Selected = true;", col.Index);
336                                                 }
337                                         }
338                                 }
339                                 for (int r = 0; r < dgv.RowCount; r++) {
340                                         for (int c = 0; c < dgv.ColumnCount; c++) {
341                                                 bool rowS = dgv.Rows [r].Selected;
342                                                 bool colS = dgv.Columns [c].Selected;
343                                                 bool cellS = dgv.Rows [r].Cells [c].Selected;
344                                                 
345                                                 if ((rowS || colS) && !cellS) {
346                                                         append (result, tab, "dgv.Rows [{0}].Cells [{1}].Selected = false;", r, c);
347                                                 } else if ((!rowS && !colS) && cellS) {
348                                                         append (result, tab, "dgv.Rows [{0}].Cells [{1}].Selected = true;", r, c);
349                                                 }
350                                         }
351                                 }
352                                 break;
353                         }
354                         
355                         if (!headers) {
356                                 data = dgv.GetClipboardContent ();
357                                 append (result, tab, "data = dgv.GetClipboardContent ();");
358                                 
359                                 if (data == null) {
360                                         append (result, tab, "Assert.IsNull (data, {0});", cs_encode ("#" + message + "-" + (counter++).ToString ()));
361                                 } else {
362                                         append (result, tab, "Assert.IsNotNull (data, {0});", cs_encode ("#" + message + "-" + (counter++).ToString ()));
363                                         
364                                         csv = data.GetData (DataFormats.CommaSeparatedValue) as string;
365                                         html = data.GetData (DataFormats.Html) as string;
366                                         utext = data.GetData (DataFormats.UnicodeText) as string;
367                                         text = data.GetData (DataFormats.Text) as string;
368                                         
369                                         append (result, tab, "Assert.AreEqual ({0}, data.GetData (DataFormats.CommaSeparatedValue), {1});", cs_encode (csv), cs_encode ("#" + message + "-" + (counter++).ToString ()));
370                                         append (result, tab, "Assert.AreEqual ({0}, data.GetData (DataFormats.Html), {1});", cs_encode (html, @"""\r\n"""), cs_encode ("#" + message + "-" + (counter++).ToString ()));
371                                         append (result, tab, "Assert.AreEqual ({0}, data.GetData (DataFormats.UnicodeText), {1});", cs_encode (utext), cs_encode ("#" + message + "-" + (counter++).ToString ()));
372                                         append (result, tab, "Assert.AreEqual ({0}, data.GetData (DataFormats.Text), {1});", cs_encode (text), cs_encode ("#" + message + "-" + (counter++).ToString ()));
373                                 }
374                         } else {
375                                 bool [] bools = new bool [] { true, false };
376                                 string [] formats = new string [] { DataFormats.Text, DataFormats.UnicodeText, DataFormats.Html, DataFormats.CommaSeparatedValue };
377
378
379                                 foreach (bool a in bools) {
380                                         foreach (bool b in bools) {
381                                                 foreach (bool c in bools) {
382                                                         foreach (bool d in bools) {
383                                                                 foreach (string format in formats) {
384                                                                         bool did_selected = false;
385                                                                         bool did_unselected = false;
386                                                                         foreach (DataGridViewRow row in dgv.Rows) {
387                                                                                 int i = row.Index;
388                                                                                 if (row.Selected) {
389                                                                                         if (did_selected)
390                                                                                                 continue;
391                                                                                         did_selected = true;
392                                                                                 } else {
393                                                                                         if (did_unselected)
394                                                                                                 continue;
395                                                                                         did_unselected = true;
396                                                                                 }
397                                                                                 row_header_cell = row.HeaderCell as DataGridViewRowHeaderTest.DataGridViewRowHeaderClipboardCell;
398                                                                                 if (row_header_cell == null) {
399                                                                                         append (result, tab, "Assert.IsNull (dgv.Rows [{0}].Headercell, {1});", row.Index, cs_encode ("#" + message + "-" + (counter++).ToString ()));
400                                                                                 } else {
401                                                                                         append (result, tab, "row_header_cell = dgv.Rows [{0}].HeaderCell as DataGridViewRowHeaderTest.DataGridViewRowHeaderClipboardCell;", row.Index);
402                                                                                         code = cs_encode (row_header_cell.GetClipboardContentPublic (i, a, b, c, d, format) as string);
403                                                                                         append (result, tab, "code = row_header_cell.GetClipboardContentPublic ({0}, {1}, {2}, {3}, {4}, \"{5}\") as string;", i, a.ToString ().ToLower (), b.ToString ().ToLower (), c.ToString ().ToLower (), d.ToString ().ToLower (), format);
404                                                                                         append (result, tab, "Assert.AreEqual ({0}, code, {1});", code, cs_encode ("#" + message + "-" + (counter++).ToString ()));
405                                                                                 }
406                                                                         }
407                                                                 }
408                                                         }
409                                                 }
410                                         }
411                                 }
412
413                                 foreach (bool a in bools) {
414                                         foreach (bool b in bools) {
415                                                 foreach (bool c in bools) {
416                                                         foreach (bool d in bools) {
417                                                                 foreach (string format in formats) {
418                                                                         bool did_selected = false;
419                                                                         bool did_unselected = false;
420                                                                         foreach (DataGridViewColumn col in dgv.Columns) {
421                                                                                 int i = -1;
422                                                                                 if (col.Index > 1)
423                                                                                         continue;
424                                                                                 if (col.Selected) {
425                                                                                         if (did_selected)
426                                                                                                 continue;
427                                                                                         did_selected = true;
428                                                                                 } else {
429                                                                                         if (did_unselected)
430                                                                                                 continue;
431                                                                                         did_unselected = true;
432                                                                                 }
433                                                                                 col_header_cell = col.HeaderCell as DataGridViewColumnHeaderTest.DataGridViewColumnHeaderClipboardCell;
434                                                                                 append (result, tab, "col_header_cell = dgv.Columns [{0}].HeaderCell as DataGridViewColumnHeaderTest.DataGridViewColumnHeaderClipboardCell;", col.Index);
435                                                                                 code = cs_encode (col_header_cell.GetClipboardContentPublic (i, a, b, c, d, format) as string);
436                                                                                 append (result, tab, "code = col_header_cell.GetClipboardContentPublic ({0}, {1}, {2}, {3}, {4}, \"{5}\") as string;", i, a.ToString ().ToLower (), b.ToString ().ToLower (), c.ToString ().ToLower (), d.ToString ().ToLower (), format);
437                                                                                 append (result, tab, "Assert.AreEqual ({0}, code, {1});", code, cs_encode ("#" + message + "-" + (counter++).ToString ()));
438                                                                         }
439                                                                 }
440                                                         }
441                                                 }
442                                         }
443                                 }
444                         }
445                         tab--;
446                         append (result, tab, "}");
447                 }
448 #endregion GenerateClipboardTest
449
450                 [Test]
451                 public void GetClipboardContents ()
452                 {
453                         DataObject data;
454                         string csv, html, utext, text;
455                         
456                         using (DataGridView dgv = DataGridViewCommon.CreateAndFill ()) {
457                                 data = dgv.GetClipboardContent ();      
458                                 Assert.IsNull (data, "#01");
459                                 
460                                 dgv.Rows [0].Cells [0].Selected = true;
461                                 
462                                 data = dgv.GetClipboardContent ();
463                                 Assert.IsNotNull (data, "#B1");
464
465                                 Assert.AreEqual (new string [] { DataFormats.CommaSeparatedValue, DataFormats.Html, DataFormats.UnicodeText, DataFormats.Text }, data.GetFormats (), "#B2");
466                                 Assert.AreEqual (new string [] { DataFormats.CommaSeparatedValue, DataFormats.Html, DataFormats.UnicodeText, DataFormats.Text }, data.GetFormats (true), "#B3");
467                                 
468                                 csv = data.GetData (DataFormats.CommaSeparatedValue) as string;
469                                 html = data.GetData (DataFormats.Html) as string;
470                                 utext = data.GetData (DataFormats.UnicodeText) as string;
471                                 text = data.GetData (DataFormats.Text) as string;
472
473                                 Assert.AreEqual ("Cell A1", csv, "CSV B");
474                                 Assert.AreEqual ("Cell A1", utext, "UTEXT B");
475                                 Assert.AreEqual ("Cell A1", text, "TEXT B");
476                                 Assert.AreEqual (string.Format(@"Version:1.0{0}" + 
477 "StartHTML:00000097{0}" + 
478 "EndHTML:00000211{0}" + 
479 "StartFragment:00000133{0}" + 
480 "EndFragment:00000175{0}" + 
481 "<HTML>{0}" + 
482 "<BODY>{0}" + 
483 "<!--StartFragment--><TABLE><TR><TD>Cell A1</TD></TR></TABLE>{0}" + 
484 "<!--EndFragment-->{0}" + 
485 "</BODY>{0}" + 
486 "</HTML>", "\r\n"), html, "HTML B");
487
488                                 dgv.Rows [1].Cells [1].Selected = true;
489
490                                 data = dgv.GetClipboardContent ();
491                                 Assert.IsNotNull (data, "#C1");
492
493                                 Assert.AreEqual (new string [] { DataFormats.CommaSeparatedValue, DataFormats.Html, DataFormats.UnicodeText, DataFormats.Text }, data.GetFormats (), "#C2");
494                                 Assert.AreEqual (new string [] { DataFormats.CommaSeparatedValue, DataFormats.Html, DataFormats.UnicodeText, DataFormats.Text }, data.GetFormats (true), "#C3");
495
496                                 csv = data.GetData (DataFormats.CommaSeparatedValue) as string;
497                                 html = data.GetData (DataFormats.Html) as string;
498                                 utext = data.GetData (DataFormats.UnicodeText) as string;
499                                 text = data.GetData (DataFormats.Text) as string;
500
501                                 Assert.AreEqual (string.Format("Cell A1,{0},Cell B2", Environment.NewLine), csv, "CSV C");
502                                 Assert.AreEqual (string.Format("Cell A1\t{0}\tCell B2", Environment.NewLine), utext, "UTEXT C");
503                                 Assert.AreEqual (string.Format("Cell A1\t{0}\tCell B2", Environment.NewLine), text, "TEXT C");
504                                 string tmp;
505                                 tmp = string.Format(@"Version:1.0{0}" +
506 "StartHTML:00000097{0}" +
507 "EndHTML:00000266{0}" +
508 "StartFragment:00000133{0}" +
509 "EndFragment:00000230{0}" +
510 "<HTML>{0}" +
511 "<BODY>{0}" +
512 "<!--StartFragment--><TABLE><TR><TD>Cell A1</TD><TD>&nbsp;</TD></TR><TR><TD>&nbsp;</TD><TD>Cell B2</TD></TR></TABLE>{0}" +
513 "<!--EndFragment-->{0}" +
514 "</BODY>{0}" +
515 "</HTML>", "\r\n");
516
517                                 Assert.AreEqual (string.Format(@"Version:1.0{0}" +
518 "StartHTML:00000097{0}" +
519 "EndHTML:00000266{0}" +
520 "StartFragment:00000133{0}" +
521 "EndFragment:00000230{0}" +
522 "<HTML>{0}" +
523 "<BODY>{0}" +
524 "<!--StartFragment--><TABLE><TR><TD>Cell A1</TD><TD>&nbsp;</TD></TR><TR><TD>&nbsp;</TD><TD>Cell B2</TD></TR></TABLE>{0}" +
525 "<!--EndFragment-->{0}" +
526 "</BODY>{0}" +
527 "</HTML>", "\r\n"), html, "HTML C");
528                         }
529                 }
530
531                 [Test]
532                 public void GetClipboardContents_HeadersAlways ()
533                 {
534                         DataObject data;
535                         string csv, html, utext, text;
536
537                         using (DataGridView dgv = DataGridViewCommon.CreateAndFill ()) {
538                                 dgv.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText;
539                                 data = dgv.GetClipboardContent ();
540                                 Assert.IsNull (data, "#01");
541
542                                 dgv.Rows [0].Cells [0].Selected = true;
543
544                                 data = dgv.GetClipboardContent ();
545                                 Assert.IsNotNull (data, "#B1");
546
547                                 Assert.AreEqual (new string [] { DataFormats.CommaSeparatedValue, DataFormats.Html, DataFormats.UnicodeText, DataFormats.Text }, data.GetFormats (), "#B2");
548                                 Assert.AreEqual (new string [] { DataFormats.CommaSeparatedValue, DataFormats.Html, DataFormats.UnicodeText, DataFormats.Text }, data.GetFormats (true), "#B3");
549
550                                 csv = data.GetData (DataFormats.CommaSeparatedValue) as string;
551                                 html = data.GetData (DataFormats.Html) as string;
552                                 utext = data.GetData (DataFormats.UnicodeText) as string;
553                                 text = data.GetData (DataFormats.Text) as string;
554
555                                 Assert.AreEqual (string.Format (",A{0},Cell A1", Environment.NewLine), csv, "CSV B");
556                                 Assert.AreEqual (string.Format ("\tA{0}\tCell A1", Environment.NewLine), utext, "UTEXT B");
557                                 Assert.AreEqual (string.Format ("\tA{0}\tCell A1", Environment.NewLine), text, "TEXT B");
558                                 Assert.AreEqual (string.Format (@"Version:1.0{0}" +
559 "StartHTML:00000097{0}" +
560 "EndHTML:00000281{0}" +
561 "StartFragment:00000133{0}" +
562 "EndFragment:00000245{0}" +
563 "<HTML>{0}" +
564 "<BODY>{0}" +
565 "<!--StartFragment--><TABLE><THEAD><TH>&nbsp;</TH><TH>A</TH></THEAD><TR><TD ALIGN=\"center\">&nbsp;</TD><TD>Cell A1</TD></TR></TABLE>{0}" +
566 "<!--EndFragment-->{0}" +
567 "</BODY>{0}" +
568 "</HTML>", "\r\n"), html, "HTML B");
569
570                                 dgv.Rows [1].Cells [1].Selected = true;
571
572                                 data = dgv.GetClipboardContent ();
573                                 Assert.IsNotNull (data, "#C1");
574
575                                 Assert.AreEqual (new string [] { DataFormats.CommaSeparatedValue, DataFormats.Html, DataFormats.UnicodeText, DataFormats.Text }, data.GetFormats (), "#C2");
576                                 Assert.AreEqual (new string [] { DataFormats.CommaSeparatedValue, DataFormats.Html, DataFormats.UnicodeText, DataFormats.Text }, data.GetFormats (true), "#C3");
577
578                                 csv = data.GetData (DataFormats.CommaSeparatedValue) as string;
579                                 html = data.GetData (DataFormats.Html) as string;
580                                 utext = data.GetData (DataFormats.UnicodeText) as string;
581                                 text = data.GetData (DataFormats.Text) as string;
582
583                                 Assert.AreEqual (string.Format (",A,B{0},Cell A1,{0},,Cell B2", Environment.NewLine), csv, "CSV C");
584                                 Assert.AreEqual (string.Format ("\tA\tB{0}\tCell A1\t{0}\t\tCell B2", Environment.NewLine), utext, "UTEXT C");
585                                 Assert.AreEqual (string.Format ("\tA\tB{0}\tCell A1\t{0}\t\tCell B2", Environment.NewLine), text, "TEXT C");
586                                 string tmp;
587                                 tmp = string.Format (@"Version:1.0{0}" +
588 "StartHTML:00000097{0}" +
589 "EndHTML:00000266{0}" +
590 "StartFragment:00000133{0}" +
591 "EndFragment:00000230{0}" +
592 "<HTML>{0}" +
593 "<BODY>{0}" +
594 "<!--StartFragment--><TABLE><TR><TD>Cell A1</TD><TD>&nbsp;</TD></TR><TR><TD>&nbsp;</TD><TD>Cell B2</TD></TR></TABLE>{0}" +
595 "<!--EndFragment-->{0}" +
596 "</BODY>{0}" +
597 "</HTML>", "\r\n");
598
599                                 Assert.AreEqual (string.Format (@"Version:1.0{0}" +
600 "StartHTML:00000097{0}" +
601 "EndHTML:00000376{0}" +
602 "StartFragment:00000133{0}" +
603 "EndFragment:00000340{0}" +
604 "<HTML>{0}" +
605 "<BODY>{0}" +
606 "<!--StartFragment--><TABLE><THEAD><TH>&nbsp;</TH><TH>A</TH><TH>B</TH></THEAD><TR><TD ALIGN=\"center\">&nbsp;</TD><TD>Cell A1</TD><TD>&nbsp;</TD></TR><TR><TD ALIGN=\"center\">&nbsp;</TD><TD>&nbsp;</TD><TD>Cell B2</TD></TR></TABLE>{0}" +
607 "<!--EndFragment-->{0}" +
608 "</BODY>{0}" +
609 "</HTML>", "\r\n"), html, "HTML C");
610                         }
611                 }
612
613                 [Test]
614                 public void GetClipboardContents_HeadersNever ()
615                 {
616                         DataObject data;
617                         string csv, html, utext, text;
618
619                         using (DataGridView dgv = DataGridViewCommon.CreateAndFill ()) {
620                                 dgv.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText;
621                                 data = dgv.GetClipboardContent ();
622                                 Assert.IsNull (data, "#01");
623
624                                 dgv.Rows [0].Cells [0].Selected = true;
625
626                                 data = dgv.GetClipboardContent ();
627                                 Assert.IsNotNull (data, "#B1");
628
629                                 Assert.AreEqual (new string [] { DataFormats.CommaSeparatedValue, DataFormats.Html, DataFormats.UnicodeText, DataFormats.Text }, data.GetFormats (), "#B2");
630                                 Assert.AreEqual (new string [] { DataFormats.CommaSeparatedValue, DataFormats.Html, DataFormats.UnicodeText, DataFormats.Text }, data.GetFormats (true), "#B3");
631
632                                 csv = data.GetData (DataFormats.CommaSeparatedValue) as string;
633                                 html = data.GetData (DataFormats.Html) as string;
634                                 utext = data.GetData (DataFormats.UnicodeText) as string;
635                                 text = data.GetData (DataFormats.Text) as string;
636
637                                 Assert.AreEqual ("Cell A1", csv, "CSV B");
638                                 Assert.AreEqual ("Cell A1", utext, "UTEXT B");
639                                 Assert.AreEqual ("Cell A1", text, "TEXT B");
640                                 Assert.AreEqual (string.Format (@"Version:1.0{0}" +
641 "StartHTML:00000097{0}" +
642 "EndHTML:00000211{0}" +
643 "StartFragment:00000133{0}" +
644 "EndFragment:00000175{0}" +
645 "<HTML>{0}" +
646 "<BODY>{0}" +
647 "<!--StartFragment--><TABLE><TR><TD>Cell A1</TD></TR></TABLE>{0}" +
648 "<!--EndFragment-->{0}" +
649 "</BODY>{0}" +
650 "</HTML>", "\r\n"), html, "HTML B");
651
652                                 dgv.Rows [1].Cells [1].Selected = true;
653
654                                 data = dgv.GetClipboardContent ();
655                                 Assert.IsNotNull (data, "#C1");
656
657                                 Assert.AreEqual (new string [] { DataFormats.CommaSeparatedValue, DataFormats.Html, DataFormats.UnicodeText, DataFormats.Text }, data.GetFormats (), "#C2");
658                                 Assert.AreEqual (new string [] { DataFormats.CommaSeparatedValue, DataFormats.Html, DataFormats.UnicodeText, DataFormats.Text }, data.GetFormats (true), "#C3");
659
660                                 csv = data.GetData (DataFormats.CommaSeparatedValue) as string;
661                                 html = data.GetData (DataFormats.Html) as string;
662                                 utext = data.GetData (DataFormats.UnicodeText) as string;
663                                 text = data.GetData (DataFormats.Text) as string;
664
665                                 Assert.AreEqual (string.Format ("Cell A1,{0},Cell B2", Environment.NewLine), csv, "CSV C");
666                                 Assert.AreEqual (string.Format ("Cell A1\t{0}\tCell B2", Environment.NewLine), utext, "UTEXT C");
667                                 Assert.AreEqual (string.Format ("Cell A1\t{0}\tCell B2", Environment.NewLine), text, "TEXT C");
668                                 string tmp;
669                                 tmp = string.Format (@"Version:1.0{0}" +
670 "StartHTML:00000097{0}" +
671 "EndHTML:00000266{0}" +
672 "StartFragment:00000133{0}" +
673 "EndFragment:00000230{0}" +
674 "<HTML>{0}" +
675 "<BODY>{0}" +
676 "<!--StartFragment--><TABLE><TR><TD>Cell A1</TD><TD>&nbsp;</TD></TR><TR><TD>&nbsp;</TD><TD>Cell B2</TD></TR></TABLE>{0}" +
677 "<!--EndFragment-->{0}" +
678 "</BODY>{0}" +
679 "</HTML>", "\r\n");
680
681                                 Assert.AreEqual (string.Format (@"Version:1.0{0}" +
682 "StartHTML:00000097{0}" +
683 "EndHTML:00000266{0}" +
684 "StartFragment:00000133{0}" +
685 "EndFragment:00000230{0}" +
686 "<HTML>{0}" +
687 "<BODY>{0}" +
688 "<!--StartFragment--><TABLE><TR><TD>Cell A1</TD><TD>&nbsp;</TD></TR><TR><TD>&nbsp;</TD><TD>Cell B2</TD></TR></TABLE>{0}" +
689 "<!--EndFragment-->{0}" +
690 "</BODY>{0}" +
691 "</HTML>", "\r\n"), html, "HTML C");
692                         }
693                 }
694                 
695                 [Test]
696                 public void EditingRow ()
697                 {
698                         using (DataGridView dgv = new DataGridView ()) {
699                                 Assert.AreEqual (true, dgv.AllowUserToAddRows, "1");
700                                 Assert.AreEqual (0, dgv.RowCount, "2");
701                                 Assert.AreEqual (-1, dgv.NewRowIndex, "3");
702                                 dgv.Columns.Add ("A", "B");
703                                 Assert.AreEqual (1, dgv.RowCount, "4");
704                                 
705                                 int added;
706                                 added = dgv.Rows.Add ("a");
707                                 Assert.AreEqual (0, added, "5");
708                         }
709                 }
710
711                 [Test] // bug 82226
712                 public void EditingRowAfterAddingColumns ()
713                 {
714                         using (DataGridView _dataGridView = new DataGridView ()) {
715                                 DataGridViewTextBoxColumn _nameTextBoxColumn;
716                                 DataGridViewTextBoxColumn _firstNameTextBoxColumn;
717                                 // 
718                                 // _nameTextBoxColumn
719                                 // 
720                                 _nameTextBoxColumn = new DataGridViewTextBoxColumn ();
721                                 _nameTextBoxColumn.HeaderText = "Name";
722                                 _dataGridView.Columns.Add (_nameTextBoxColumn);
723                                 // 
724                                 // _firstNameTextBoxColumn
725                                 // 
726                                 _firstNameTextBoxColumn = new DataGridViewTextBoxColumn ();
727                                 _firstNameTextBoxColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
728                                 _firstNameTextBoxColumn.HeaderText = "First Name";
729                                 _dataGridView.Columns.Add (_firstNameTextBoxColumn);
730
731                                 _dataGridView.Rows.Add ("de Icaza", "Miguel");
732                                 _dataGridView.Rows.Add ("Toshok", "Chris");
733                                 _dataGridView.Rows.Add ("Harper", "Jackson");
734                                 
735                                 Assert.AreEqual (4, _dataGridView.RowCount, "#01");
736                                 Assert.AreEqual (2, _dataGridView.Rows [3].Cells.Count, "#02");
737                         }
738                 }
739
740                 [Test]
741                 public void bug_81918 ()
742                 {
743                         using (DataGridView dgv = new DataGridView ()) {
744                                 DataGridViewColumn col = new DataGridViewComboBoxColumn ();
745                                 
746                                 dgv.Columns.Add (col);
747                                 
748                                 dgv.Rows.Add ("a");
749                                 
750                                 DataGridViewComboBoxCell cell = (DataGridViewComboBoxCell) dgv [0, 0];
751                         }
752                 }
753
754                 [Test]
755                 public void SelectedRowsTest ()
756                 {
757                         using (DataGridView dgv = DataGridViewCommon.CreateAndFillBig ()) {
758                                 dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
759                                 dgv.Rows [1].Selected = true;
760                                 Assert.AreEqual (1, dgv.SelectedRows.Count, "1-1");
761                                 Assert.AreEqual (1, dgv.SelectedRows [0].Index, "1-2");
762                                 dgv.Rows [3].Selected = true;
763                                 Assert.AreEqual (2, dgv.SelectedRows.Count, "1-3");
764                                 Assert.AreEqual (3, dgv.SelectedRows [0].Index, "1-4");
765                                 Assert.AreEqual (1, dgv.SelectedRows [1].Index, "1-5");
766                                 dgv.Rows [2].Selected = true;
767                                 Assert.AreEqual (3, dgv.SelectedRows.Count, "1-6");
768                                 Assert.AreEqual (2, dgv.SelectedRows [0].Index, "1-7");
769                                 Assert.AreEqual (3, dgv.SelectedRows [1].Index, "1-8");
770                                 Assert.AreEqual (1, dgv.SelectedRows [2].Index, "1-9");
771                         }
772
773                         using (DataGridView dgv = DataGridViewCommon.CreateAndFillBig ()) {
774                                 dgv.SelectionMode = DataGridViewSelectionMode.CellSelect;
775                                 dgv.Rows [1].Selected = true;
776                                 Assert.AreEqual (0, dgv.SelectedRows.Count, "3-1");
777                                 dgv.Rows [3].Selected = true;
778                                 Assert.AreEqual (0, dgv.SelectedRows.Count, "3-3");
779                                 dgv.Rows [2].Selected = true;
780                                 Assert.AreEqual (0, dgv.SelectedRows.Count, "3-6");
781                         }
782
783                         using (DataGridView dgv = DataGridViewCommon.CreateAndFillBig ()) {
784                                 foreach (DataGridViewColumn col in dgv.Columns)
785                                         col.SortMode = DataGridViewColumnSortMode.NotSortable;
786                                 dgv.SelectionMode = DataGridViewSelectionMode.ColumnHeaderSelect;
787                                 dgv.Rows [1].Selected = true;
788                                 Assert.AreEqual (0, dgv.SelectedRows.Count, "4-1");
789                                 dgv.Rows [3].Selected = true;
790                                 Assert.AreEqual (0, dgv.SelectedRows.Count, "4-3");
791                                 dgv.Rows [2].Selected = true;
792                                 Assert.AreEqual (0, dgv.SelectedRows.Count, "4-6");
793                         }
794
795                         using (DataGridView dgv = DataGridViewCommon.CreateAndFillBig ()) {
796                                 foreach (DataGridViewColumn col in dgv.Columns)
797                                         col.SortMode = DataGridViewColumnSortMode.NotSortable;
798                                 dgv.SelectionMode = DataGridViewSelectionMode.FullColumnSelect;
799                                 dgv.Rows [1].Selected = true;
800                                 Assert.AreEqual (0, dgv.SelectedRows.Count, "5-1");
801                                 dgv.Rows [3].Selected = true;
802                                 Assert.AreEqual (0, dgv.SelectedRows.Count, "5-3");
803                                 dgv.Rows [2].Selected = true;
804                                 Assert.AreEqual (0, dgv.SelectedRows.Count, "5-6");
805                         }
806                 }
807
808                 [Test] // bug #325979
809                 public void SelectedRows_FindColumnByName ()
810                 {
811                         DataTable dt = new DataTable ();
812                         dt.Columns.Add ("Date", typeof (DateTime));
813                         dt.Columns.Add ("Registered", typeof (bool));
814                         dt.Columns.Add ("Event", typeof (string));
815
816                         DataRow row = dt.NewRow ();
817                         row ["Date"] = new DateTime (2007, 2, 3);
818                         row ["Event"] = "one";
819                         row ["Registered"] = false;
820                         dt.Rows.Add (row);
821
822                         row = dt.NewRow ();
823                         row ["Date"] = new DateTime (2008, 3, 4);
824                         row ["Event"] = "two";
825                         row ["Registered"] = true;
826                         dt.Rows.Add (row);
827
828                         DataGridView dgv = new DataGridView ();
829                         dgv.DataSource = dt;
830
831                         Form form = new Form ();
832                         form.ShowInTaskbar = false;
833                         form.Controls.Add (dgv);
834                         form.Show ();
835
836                         dgv.Rows [1].Selected = true;
837
838                         DataGridViewCell cell = dgv.SelectedRows [0].Cells ["DaTE"];
839                         Assert.IsNotNull (cell, "#A1");
840                         Assert.IsNotNull (cell.OwningColumn, "#A2");
841                         Assert.AreEqual ("Date", cell.OwningColumn.Name, "#A3");
842                         Assert.IsNotNull (cell.Value, "#A4");
843                         Assert.AreEqual (new DateTime (2008, 3, 4), cell.Value, "#A5");
844
845                         cell = dgv.SelectedRows [0].Cells ["Event"];
846                         Assert.IsNotNull (cell, "#B1");
847                         Assert.IsNotNull (cell.OwningColumn, "#B2");
848                         Assert.AreEqual ("Event", cell.OwningColumn.Name, "#B3");
849                         Assert.IsNotNull (cell.Value, "#B3");
850                         Assert.AreEqual ("two", cell.Value, "#B4");
851
852                         form.Dispose ();
853                 }
854
855                 [Test]
856                 public void SelectedColumnsTest ()
857                 {
858                         using (DataGridView dgv = DataGridViewCommon.CreateAndFillBig ()) {
859                                 foreach (DataGridViewColumn col in dgv.Columns)
860                                         col.SortMode = DataGridViewColumnSortMode.NotSortable;
861                                 dgv.SelectionMode = DataGridViewSelectionMode.FullColumnSelect;
862                                 dgv.Columns [1].Selected = true;
863                                 Assert.AreEqual (1, dgv.SelectedColumns.Count, "1-1");
864                                 Assert.AreEqual (1, dgv.SelectedColumns [0].Index, "1-2");
865                                 dgv.Columns [3].Selected = true;
866                                 Assert.AreEqual (2, dgv.SelectedColumns.Count, "1-3");
867                                 Assert.AreEqual (3, dgv.SelectedColumns [0].Index, "1-4");
868                                 Assert.AreEqual (1, dgv.SelectedColumns [1].Index, "1-5");
869                                 dgv.Columns [2].Selected = true;
870                                 Assert.AreEqual (3, dgv.SelectedColumns.Count, "1-6");
871                                 Assert.AreEqual (2, dgv.SelectedColumns [0].Index, "1-7");
872                                 Assert.AreEqual (3, dgv.SelectedColumns [1].Index, "1-8");
873                                 Assert.AreEqual (1, dgv.SelectedColumns [2].Index, "1-9");
874                         }
875
876                         using (DataGridView dgv = DataGridViewCommon.CreateAndFillBig ()) {
877                                 foreach (DataGridViewColumn col in dgv.Columns)
878                                         col.SortMode = DataGridViewColumnSortMode.NotSortable;
879                                 dgv.SelectionMode = DataGridViewSelectionMode.ColumnHeaderSelect;
880                                 dgv.Columns [1].Selected = true;
881                                 Assert.AreEqual (1, dgv.SelectedColumns.Count, "2-1");
882                                 Assert.AreEqual (1, dgv.SelectedColumns [0].Index, "2-2");
883                                 dgv.Columns [3].Selected = true;
884                                 Assert.AreEqual (2, dgv.SelectedColumns.Count, "2-3");
885                                 Assert.AreEqual (3, dgv.SelectedColumns [0].Index, "2-4");
886                                 Assert.AreEqual (1, dgv.SelectedColumns [1].Index, "2-5");
887                                 dgv.Columns [2].Selected = true;
888                                 Assert.AreEqual (3, dgv.SelectedColumns.Count, "2-6");
889                                 Assert.AreEqual (2, dgv.SelectedColumns [0].Index, "2-7");
890                                 Assert.AreEqual (3, dgv.SelectedColumns [1].Index, "2-8");
891                                 Assert.AreEqual (1, dgv.SelectedColumns [2].Index, "2-9");
892                         }
893
894                         using (DataGridView dgv = DataGridViewCommon.CreateAndFillBig ()) {
895                                 dgv.SelectionMode = DataGridViewSelectionMode.CellSelect;
896                                 dgv.Columns [1].Selected = true;
897                                 Assert.AreEqual (0, dgv.SelectedColumns.Count, "3-1");
898                                 dgv.Columns [3].Selected = true;
899                                 Assert.AreEqual (0, dgv.SelectedColumns.Count, "3-3");
900                                 dgv.Columns [2].Selected = true;
901                                 Assert.AreEqual (0, dgv.SelectedColumns.Count, "3-6");
902                         }
903
904                         using (DataGridView dgv = DataGridViewCommon.CreateAndFillBig ()) {
905                                 foreach (DataGridViewColumn col in dgv.Columns)
906                                         col.SortMode = DataGridViewColumnSortMode.NotSortable;
907                                 dgv.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect;
908                                 dgv.Columns [1].Selected = true;
909                                 Assert.AreEqual (0, dgv.SelectedColumns.Count, "4-1");
910                                 dgv.Columns [3].Selected = true;
911                                 Assert.AreEqual (0, dgv.SelectedColumns.Count, "4-3");
912                                 dgv.Columns [2].Selected = true;
913                                 Assert.AreEqual (0, dgv.SelectedColumns.Count, "4-6");
914                         }
915
916                         using (DataGridView dgv = DataGridViewCommon.CreateAndFillBig ()) {
917                                 foreach (DataGridViewColumn col in dgv.Columns)
918                                         col.SortMode = DataGridViewColumnSortMode.NotSortable;
919                                 dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
920                                 dgv.Columns [1].Selected = true;
921                                 Assert.AreEqual (0, dgv.SelectedColumns.Count, "5-1");
922                                 dgv.Columns [3].Selected = true;
923                                 Assert.AreEqual (0, dgv.SelectedColumns.Count, "5-3");
924                                 dgv.Columns [2].Selected = true;
925                                 Assert.AreEqual (0, dgv.SelectedColumns.Count, "5-6");
926                         }
927                 }
928
929                 [Test]
930                 public void TopLeftHeaderCellTest ()
931                 {
932                         Assert.Ignore("Missing quite a few bits still");
933                         
934                         using (DataGridView dgv = new DataGridView ()) {
935                                 DataGridViewHeaderCell cell = dgv.TopLeftHeaderCell;
936                                 
937                                 cell = dgv.TopLeftHeaderCell;
938
939                                 Assert.IsNotNull (cell, "#01");
940                                 Assert.AreEqual (cell.DataGridView, dgv, "#02");
941                                 Assert.AreEqual ("DataGridViewTopLeftHeaderCell", cell.GetType ().Name, "#03");
942                                                                 
943                                 Assert.IsNotNull (cell.AccessibilityObject, "#cell.AccessibilityObject");
944                                 Assert.AreEqual (-1, cell.ColumnIndex, "#cell.ColumnIndex");
945                                 // /* NIE for the moment... */ Assert.IsNotNull (cell.ContentBounds, "#cell.ContentBounds");
946                                 Assert.IsNull (cell.ContextMenuStrip, "#cell.ContextMenuStrip");
947                                 Assert.IsNotNull (cell.DataGridView, "#cell.DataGridView");
948                                 Assert.IsNull (cell.DefaultNewRowValue, "#cell.DefaultNewRowValue");
949                                 Assert.AreEqual (false, cell.Displayed, "#cell.Displayed");
950                                 // /* NIE for the moment... */ Assert.AreEqual (@"", cell.EditedFormattedValue, "#cell.EditedFormattedValue");
951                                 Assert.IsNotNull (cell.EditType, "#cell.EditType");
952                                 Assert.IsNotNull (cell.ErrorIconBounds, "#cell.ErrorIconBounds");
953                                 Assert.AreEqual (@"", cell.ErrorText, "#cell.ErrorText");
954                                 // /* NIE for the moment... */ Assert.AreEqual (@"", cell.FormattedValue, "#cell.FormattedValue");
955                                 Assert.IsNotNull (cell.FormattedValueType, "#cell.FormattedValueType");
956                                 // /* NIE for the moment... */ Assert.AreEqual (true, cell.Frozen, "#cell.Frozen");
957                                 Assert.AreEqual (false, cell.HasStyle, "#cell.HasStyle");
958                                 Assert.AreEqual (DataGridViewElementStates.Frozen | DataGridViewElementStates.ReadOnly | DataGridViewElementStates.Resizable | DataGridViewElementStates.ResizableSet | DataGridViewElementStates.Visible, cell.InheritedState, "#cell.InheritedState");
959                                 Assert.IsNotNull (cell.InheritedStyle, "#cell.InheritedStyle");
960                                 try {
961                                         object zxf = cell.IsInEditMode;
962                                         TestHelper.RemoveWarning (zxf);
963                                         Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#cell.IsInEditMode");
964                                 } catch (InvalidOperationException ex) {
965                                         Assert.AreEqual (@"Operation cannot be performed on a cell of a shared row.", ex.Message);
966                                 } catch (Exception ex) {
967                                         Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#cell.IsInEditMode");
968                                 }
969                                 Assert.IsNull (cell.OwningColumn, "#cell.OwningColumn");
970                                 Assert.IsNull (cell.OwningRow, "#cell.OwningRow");
971                                 Assert.IsNotNull (cell.PreferredSize, "#cell.PreferredSize");
972                                 Assert.AreEqual (true, cell.ReadOnly, "#cell.ReadOnly");
973                                 Assert.AreEqual (true, cell.Resizable, "#cell.Resizable");
974                                 Assert.AreEqual (-1, cell.RowIndex, "#cell.RowIndex");
975                                 Assert.AreEqual (false, cell.Selected, "#cell.Selected");
976                                 Assert.IsNotNull (cell.Size, "#cell.Size");
977                                 Assert.AreEqual (DataGridViewElementStates.None, cell.State, "#cell.State");
978                                 if (cell.HasStyle)
979                                         Assert.IsNotNull (cell.Style, "#cell.Style");
980                                 Assert.IsNull (cell.Tag, "#cell.Tag");
981                                 Assert.AreEqual (@"", cell.ToolTipText, "#cell.ToolTipText");
982                                 Assert.IsNull (cell.Value, "#cell.Value");
983                                 Assert.IsNotNull (cell.ValueType, "#cell.ValueType");
984                                 Assert.AreEqual (true, cell.Visible, "#cell.Visible");
985                         }
986                 }
987
988                 [Test]
989                 public void TestDefaultValues ()
990                 {
991                         DataGridView grid = new DataGridView ();
992                         Assert.AreEqual (true, grid.AllowUserToAddRows, "#A1");
993                         Assert.AreEqual (true, grid.AllowUserToDeleteRows, "#A2");
994                         Assert.AreEqual (false, grid.AllowUserToOrderColumns, "#A3");
995                         Assert.AreEqual (true, grid.AllowUserToResizeColumns, "#A4");
996                         Assert.AreEqual (true, grid.AllowUserToResizeRows, "#A5");
997                         Assert.AreEqual (new DataGridViewCellStyle(), grid.AlternatingRowsDefaultCellStyle, "#A6");
998                         Assert.AreEqual (true, grid.AutoGenerateColumns, "#A7");
999                         Assert.AreEqual (DataGridViewAutoSizeRowsMode.None, grid.AutoSizeRowsMode, "#A8");
1000                         Assert.AreEqual (Control.DefaultBackColor, grid.BackColor, "#A9");
1001                         Assert.AreEqual (SystemColors.AppWorkspace, grid.BackgroundColor, "#A10");
1002                         Assert.AreEqual (BorderStyle.FixedSingle, grid.BorderStyle, "#A11");
1003                         Assert.AreEqual (DataGridViewClipboardCopyMode.EnableWithAutoHeaderText, grid.ClipboardCopyMode, "#A12");
1004                         Assert.AreEqual (DataGridViewColumnHeadersHeightSizeMode.EnableResizing, grid.ColumnHeadersHeightSizeMode, "#A21");
1005                         Assert.AreEqual (true, grid.ColumnHeadersVisible, "#A22");
1006                         Assert.AreEqual (String.Empty, grid.DataMember, "#A23");
1007                         Assert.AreEqual (DataGridViewEditMode.EditOnKeystrokeOrF2, grid.EditMode, "#A31");
1008                         Assert.AreEqual (Control.DefaultFont, grid.Font, "#A32");
1009                         Assert.AreEqual (Control.DefaultForeColor, grid.ForeColor, "#A33");
1010                         Assert.AreEqual (Color.FromKnownColor(KnownColor.ControlDark), grid.GridColor, "#A34");
1011                         Assert.AreEqual (true, grid.MultiSelect, "#A35");
1012                         Assert.AreEqual (grid.Rows.Count - 1, grid.NewRowIndex, "#A36");
1013                         Assert.AreEqual (Padding.Empty, grid.Padding, "#A37");
1014                         Assert.AreEqual (false, grid.ReadOnly, "#A38");
1015                         Assert.AreEqual (true, grid.RowHeadersVisible, "#A39");
1016                         Assert.AreEqual (41, grid.RowHeadersWidth, "#A40");
1017                         Assert.AreEqual (DataGridViewSelectionMode.RowHeaderSelect, grid.SelectionMode, "#A41");
1018                         Assert.AreEqual (true, grid.ShowCellErrors, "#A42");
1019                         Assert.AreEqual (true, grid.ShowEditingIcon, "#A43");
1020                         Assert.AreEqual (Cursors.Default, grid.UserSetCursor, "#A44");
1021                         Assert.AreEqual (false, grid.VirtualMode, "#A45");
1022                 }
1023
1024 #region AutoSizeColumnsModeExceptions
1025
1026                 [Test]
1027                 [ExpectedException (typeof (InvalidEnumArgumentException))]
1028                 public void TestAutoSizeColumnsModeInvalidEnumArgumentException ()
1029                 {
1030                         DataGridView grid = new DataGridView();
1031                         grid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill | DataGridViewAutoSizeColumnsMode.None;
1032                 }
1033
1034                 [Test]
1035                 [ExpectedException (typeof (InvalidOperationException))]
1036                 public void TestAutoSizeColumnsModeInvalidOperationException1 ()
1037                 {
1038                         DataGridView grid = new DataGridView ();
1039                         grid.ColumnHeadersVisible = false;
1040                         DataGridViewColumn col = new DataGridViewColumn ();
1041                         col.AutoSizeMode = DataGridViewAutoSizeColumnMode.NotSet;
1042                         grid.Columns.Add (col);
1043                         grid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.ColumnHeader;
1044                 }
1045
1046                 [Test]
1047                 [ExpectedException (typeof (InvalidOperationException))]
1048                 public void TestAutoSizeColumnsModeInvalidOperationException2 ()
1049                 {
1050                         DataGridView grid = new DataGridView ();
1051                         DataGridViewColumn col = new DataGridViewColumn ();
1052                         col.AutoSizeMode = DataGridViewAutoSizeColumnMode.NotSet;
1053                         col.Frozen = true;
1054                         grid.Columns.Add (col);
1055                         grid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
1056                 }
1057
1058 #endregion
1059
1060 #region AutoSizeRowsModeExceptions
1061
1062                 [Test]
1063                 [ExpectedException (typeof (InvalidEnumArgumentException))]
1064                 public void TestAutoSizeRowsModeInvalidEnumArgumentException ()
1065                 {
1066                         DataGridView grid = new DataGridView ();
1067                         grid.AutoSizeRowsMode = (DataGridViewAutoSizeRowsMode) 4;
1068                 }
1069
1070                 [Test]
1071                 [ExpectedException (typeof (InvalidOperationException))]
1072                 public void TestAutoSizeRowsModeInvalidOperationException1 ()
1073                 {
1074                         DataGridView grid = new DataGridView ();
1075                         grid.RowHeadersVisible = false;
1076                         grid.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllHeaders;
1077                 }
1078
1079                 [Test]
1080                 [ExpectedException (typeof (InvalidOperationException))]
1081                 public void TestAutoSizeRowsModeInvalidOperationException2 ()
1082                 {
1083                         DataGridView grid = new DataGridView ();
1084                         grid.RowHeadersVisible = false;
1085                         grid.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedHeaders;
1086                 }
1087
1088 #endregion
1089
1090                 [Test]
1091                 public void AutoResizeColumTest ()
1092                 {
1093                         using (Form f = new Form ()) {
1094                                 f.Show ();
1095                                 using (DataGridView dgv = new DataGridView ()) {
1096                                         f.Controls.Add (dgv);
1097                                         
1098                                         DataGridViewColumn col, col2, col3;
1099                                         
1100                                         Assert.AreEqual ("{Width=240, Height=150}", dgv.ClientSize.ToString (), "#01");
1101                                         
1102                                         col = new DataGridViewColumn ();
1103                                         col.MinimumWidth = 20;
1104                                         col.FillWeight = 20;
1105                                         col.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
1106                                         col.CellTemplate = new DataGridViewTextBoxCell ();
1107                                         
1108                                         Assert.AreEqual (100, col.Width, "#02");
1109                                         dgv.Columns.Add (col);
1110                                         
1111                                         Assert.AreEqual (197, col.Width, "#03");
1112
1113                                         col2 = new DataGridViewColumn ();
1114                                         col2.MinimumWidth = 20;
1115                                         col2.FillWeight = 40;
1116                                         col2.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
1117                                         col2.CellTemplate = new DataGridViewTextBoxCell (); ;
1118                                         dgv.Columns.Add (col2);
1119
1120                                         Assert.AreEqual (66, col.Width, "#04");
1121                                         Assert.AreEqual (131, col2.Width, "#05");
1122
1123                                         col3 = new DataGridViewColumn ();
1124                                         col3.MinimumWidth = 20;
1125                                         col3.FillWeight = 5;
1126                                         col3.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
1127                                         col3.CellTemplate = new DataGridViewTextBoxCell (); ;
1128                                         dgv.Columns.Add (col3);
1129
1130                                         Assert.AreEqual (59, col.Width, "#04");
1131                                         Assert.AreEqual (118, col2.Width, "#05");
1132                                         Assert.AreEqual (20, col3.Width, "#05");
1133                                 }
1134                         }
1135                 }
1136
1137                 [Test]
1138                 public void ControlsTest ()
1139                 {
1140                         using (DataGridView grid = new DataGridView ()) {
1141                                 Assert.AreEqual ("DataGridViewControlCollection", grid.Controls.GetType ().Name, "#01");
1142                                 Assert.AreEqual (2, grid.Controls.Count, "#02");
1143                         }
1144                 }
1145         
1146                 [Test]
1147                 [ExpectedException (typeof (ArgumentException))]
1148                 public void TestBackgroundColorArgumentException ()
1149                 {
1150                         DataGridView grid = new DataGridView ();
1151                         grid.BackgroundColor = Color.Empty;
1152                 }
1153
1154                 [Test]
1155                 [ExpectedException(typeof(InvalidEnumArgumentException))]
1156                 public void TestBorderStyleInvalidEnumArgumentException ()
1157                 {
1158                         DataGridView grid = new DataGridView ();
1159                         grid.BorderStyle = BorderStyle.FixedSingle | BorderStyle.Fixed3D;
1160                 }
1161
1162                 [Test]
1163                 public void ColumnCount ()
1164                 {
1165                         DataGridView dgv = new DataGridView ();
1166
1167                         dgv.RowCount = 10;
1168                         dgv.ColumnCount = 2;
1169
1170                         Assert.AreEqual (10, dgv.RowCount, "A1");
1171                         Assert.AreEqual (2, dgv.ColumnCount, "A2");
1172
1173                         dgv.ColumnCount = 1;
1174
1175                         Assert.AreEqual (10, dgv.RowCount, "B1");
1176                         Assert.AreEqual (1, dgv.ColumnCount, "B2");
1177
1178                         dgv.ColumnCount = 3;
1179
1180                         Assert.AreEqual (10, dgv.RowCount, "C1");
1181                         Assert.AreEqual (3, dgv.ColumnCount, "C2");
1182
1183
1184                         dgv.ColumnCount = 0;
1185
1186                         Assert.AreEqual (0, dgv.RowCount, "D1");
1187                         Assert.AreEqual (0, dgv.ColumnCount, "D2");
1188
1189                         Assert.AreEqual (0, dgv.ColumnCount, "E1");
1190
1191                         try {
1192                                 dgv.ColumnCount = -1;
1193                                 Assert.Fail ("F1");
1194                         } catch (ArgumentOutOfRangeException ex) {
1195                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "F2");
1196                                 Assert.IsNotNull (ex.Message, "F3");
1197                                 Assert.IsNotNull (ex.ParamName, "F4");
1198                                 Assert.AreEqual ("ColumnCount", ex.ParamName, "F5");
1199                                 Assert.IsNull (ex.InnerException, "F6");
1200                         }
1201                 }
1202
1203                 [Test]
1204                 public void ColumnCountIncrease ()
1205                 {
1206                         DataGridView dgv = new DataGridView ();
1207                         dgv.ColumnCount = 1;
1208                         
1209                         // Increasing the ColumnCount adds TextBoxColumns, not generic columns
1210                         Assert.AreEqual ("System.Windows.Forms.DataGridViewTextBoxColumn", dgv.Columns[0].GetType ().ToString (), "A1");
1211                 }
1212
1213
1214                 [Test]
1215                 public void ColumnCountDecrease ()
1216                 {
1217                         DataGridView dgv = new DataGridView ();
1218                         dgv.ColumnCount = 6;
1219                         Assert.AreEqual (6, dgv.ColumnCount, "A1");
1220
1221                         dgv.ColumnCount = 3;
1222                         Assert.AreEqual (3, dgv.ColumnCount, "A2");
1223                         
1224                         // Increasing the ColumnCount adds TextBoxColumns, not generic columns
1225                         Assert.AreEqual ("System.Windows.Forms.DataGridViewTextBoxColumn", dgv.Columns[0].GetType ().ToString (), "A3");
1226                         Assert.AreEqual ("System.Windows.Forms.DataGridViewTextBoxColumn", dgv.Columns[1].GetType ().ToString (), "A4");
1227                         Assert.AreEqual ("System.Windows.Forms.DataGridViewTextBoxColumn", dgv.Columns[2].GetType ().ToString (), "A5");
1228                 }
1229
1230                 private class DataItem
1231                 {
1232                         public string Text {
1233                                 get { return String.Empty; }
1234                         }
1235
1236                         [Browsable (false)]
1237                         public string NotVisible {
1238                                 get { return String.Empty; }
1239                         }
1240                 }
1241
1242                 [Test]
1243                 public void NoDuplicateAutoGeneratedColumn ()
1244                 {
1245                         List<DataItem> dataList = new List<DataItem> ();
1246                         dataList.Add (new DataItem ());
1247                         dataList.Add (new DataItem ());
1248
1249                         DataGridViewTextBoxColumn column = new DataGridViewTextBoxColumn ();
1250                         column.DataPropertyName = "Text";
1251                         column.HeaderText = "Custom Column";
1252                         grid.Columns.Add (column);
1253
1254                         grid.DataSource = dataList;
1255                         // Test that the column autogeneration hasn't generated duplicate column 
1256                         // for the property Text
1257                         Assert.AreEqual (1, grid.Columns.Count, "#1");
1258                         Assert.AreEqual ("Custom Column", grid.Columns[0].HeaderText, "#2");
1259                 }
1260
1261                 [Test]
1262                 [ExpectedException (typeof (InvalidOperationException))]
1263                 public void TestColumnCountInvalidOperationException ()
1264                 {
1265                         DataGridView grid = new DataGridView ();
1266                         grid.DataSource = new ArrayList ();
1267                         grid.ColumnCount = 0;
1268                 }
1269
1270                 [Test]
1271                 public void ColumnHeadersHeight ()
1272                 {
1273                         DataGridView grid = new DataGridView ();
1274                         Assert.AreEqual (23, grid.ColumnHeadersHeight, "#A1");
1275                         grid.ColumnHeadersHeight = 4;
1276                         Assert.AreEqual (4, grid.ColumnHeadersHeight, "#A2");
1277                         grid.ColumnHeadersHeight = 32768;
1278                         Assert.AreEqual (32768, grid.ColumnHeadersHeight, "#A3");
1279
1280                         try {
1281                                 grid.ColumnHeadersHeight = 3;
1282                                 Assert.Fail ("#B1");
1283                         } catch (ArgumentOutOfRangeException ex) {
1284                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
1285                                 Assert.IsNotNull (ex.Message, "#B3");
1286                                 Assert.IsNotNull (ex.ParamName, "#B4");
1287                                 Assert.AreEqual ("ColumnHeadersHeight", ex.ParamName, "#B5");
1288                                 Assert.IsNull (ex.InnerException, "#B6");
1289                         }
1290
1291                         try {
1292                                 grid.ColumnHeadersHeight = 32769;
1293                                 Assert.Fail ("#C1");
1294                         } catch (ArgumentOutOfRangeException ex) {
1295                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#C2");
1296                                 Assert.IsNotNull (ex.Message, "#C3");
1297                                 Assert.IsNotNull (ex.ParamName, "#C4");
1298                                 Assert.AreEqual ("ColumnHeadersHeight", ex.ParamName, "#C5");
1299                                 Assert.IsNull (ex.InnerException, "#C6");
1300                         }
1301                 }
1302
1303                 [Test]
1304                 [ExpectedException (typeof (InvalidEnumArgumentException))]
1305                 public void TestColumnHeadersHeightSizeModeInvalidEnumArgumentException ()
1306                 {
1307                         DataGridView grid = new DataGridView ();
1308                         grid.ColumnHeadersHeightSizeMode = (DataGridViewColumnHeadersHeightSizeMode) 3;
1309                 }
1310
1311                 [Test]
1312                 public void RowHeadersWidth ()
1313                 {
1314                         DataGridView grid = new DataGridView();
1315                         Assert.AreEqual (41, grid.RowHeadersWidth, "#A1");
1316                         grid.RowHeadersWidth = 4;
1317                         Assert.AreEqual (4, grid.RowHeadersWidth, "#A2");
1318                         grid.RowHeadersWidth = 32768;
1319                         Assert.AreEqual (32768, grid.RowHeadersWidth, "#A3");
1320
1321                         try {
1322                                 grid.RowHeadersWidth = 3;
1323                                 Assert.Fail ("#B1");
1324                         } catch (ArgumentOutOfRangeException ex) {
1325                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
1326                                 Assert.IsNotNull (ex.Message, "#B3");
1327                                 Assert.IsNotNull (ex.ParamName, "#B4");
1328                                 Assert.AreEqual ("RowHeadersWidth", ex.ParamName, "#B5");
1329                                 Assert.IsNull (ex.InnerException, "#B6");
1330                         }
1331
1332                         try {
1333                                 grid.RowHeadersWidth = 32769;
1334                                 Assert.Fail ("#C1");
1335                         } catch (ArgumentOutOfRangeException ex) {
1336                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#C2");
1337                                 Assert.IsNotNull (ex.Message, "#C3");
1338                                 Assert.IsNotNull (ex.ParamName, "#C4");
1339                                 Assert.AreEqual ("RowHeadersWidth", ex.ParamName, "#C5");
1340                                 Assert.IsNull (ex.InnerException, "#C6");
1341                         }
1342                 }
1343
1344                 [Test]
1345                 [ExpectedException (typeof (InvalidEnumArgumentException))]
1346                 public void TestDataGridViewRowHeadersWidthSizeModeInvalidEnumArgumentException () {
1347                         DataGridView grid = new DataGridView ();
1348                         grid.RowHeadersWidthSizeMode = (DataGridViewRowHeadersWidthSizeMode) 5;
1349                 }
1350
1351                 [Test]
1352                 [ExpectedException (typeof (InvalidEnumArgumentException))]
1353                 public void TestScrollBarsInvalidEnumArgumentException ()
1354                 {
1355                         DataGridView grid = new DataGridView ();
1356                         grid.ScrollBars = (ScrollBars) 4;
1357                 }
1358
1359                 [Test]
1360                 [ExpectedException (typeof (InvalidEnumArgumentException))]
1361                 public void TestSelectionModeInvalidEnumArgumentException ()
1362                 {
1363                         DataGridView grid = new DataGridView ();
1364                         grid.SelectionMode = (DataGridViewSelectionMode) 5;
1365                 }
1366
1367                 [Test]
1368                 [ExpectedException (typeof (InvalidEnumArgumentException))]
1369                 public void TestAutoResizeRowsInvalidEnumArgumentException ()
1370                 {
1371                         DataGridView grid = new DataGridView ();
1372                         grid.AutoResizeRows ((DataGridViewAutoSizeRowsMode) 4);
1373                 }
1374
1375                 [Test]
1376                 [ExpectedException (typeof (InvalidOperationException))]
1377                 public void TestAutoResizeRowsInvalidOperationException1 ()
1378                 {
1379                         DataGridView grid = new DataGridView ();
1380                         grid.RowHeadersVisible = false;
1381                         grid.AutoResizeRows (DataGridViewAutoSizeRowsMode.AllHeaders);
1382                 }
1383
1384                 [Test]
1385                 [ExpectedException (typeof (InvalidOperationException))]
1386                 public void TestAutoResizeRowsInvalidOperationException2 ()
1387                 {
1388                         DataGridView grid = new DataGridView ();
1389                         grid.RowHeadersVisible = false;
1390                         grid.AutoResizeRows (DataGridViewAutoSizeRowsMode.DisplayedHeaders);
1391                 }
1392
1393                 [Test]
1394                 [ExpectedException (typeof (ArgumentException))]
1395                 public void TestAutoResizeRowsArgumentException ()
1396                 {
1397                         DataGridView grid = new DataGridView ();
1398                         grid.AutoResizeRows (DataGridViewAutoSizeRowsMode.None);
1399                 }
1400
1401                 [Test]
1402                 public void DefaultSize ()
1403                 {
1404                         MockDataGridView grid = new MockDataGridView ();
1405                         Assert.AreEqual (new Size (240, 150), grid.default_size, "#1");
1406                         Assert.AreEqual (new Size (240, 150), grid.Size, "#2");
1407                 }
1408
1409                 [Test]
1410                 public void ColumnHeadersDefaultCellStyle ()
1411                 {
1412                         DataGridView grid = new DataGridView();
1413                         Assert.AreEqual (SystemColors.Control, grid.ColumnHeadersDefaultCellStyle.BackColor, "#A1");
1414                         Assert.AreEqual (SystemColors.WindowText,  grid.ColumnHeadersDefaultCellStyle.ForeColor, "#A2");
1415                         Assert.AreEqual (SystemColors.Highlight, grid.ColumnHeadersDefaultCellStyle.SelectionBackColor, "#A3");
1416                         Assert.AreEqual (SystemColors.HighlightText, grid.ColumnHeadersDefaultCellStyle.SelectionForeColor, "#A4");
1417                         Assert.AreSame (grid.Font, grid.ColumnHeadersDefaultCellStyle.Font, "#A5");
1418                         Assert.AreEqual (DataGridViewContentAlignment.MiddleLeft, grid.ColumnHeadersDefaultCellStyle.Alignment, "#A6");
1419                         Assert.AreEqual (DataGridViewTriState.True, grid.ColumnHeadersDefaultCellStyle.WrapMode, "#A7");
1420                 }
1421
1422                 [Test]
1423                 public void DefaultCellStyle ()
1424                 {
1425                         DataGridView grid = new DataGridView();
1426                         Assert.AreEqual (SystemColors.Window, grid.DefaultCellStyle.BackColor, "#A1");
1427                         Assert.AreEqual (SystemColors.ControlText,  grid.DefaultCellStyle.ForeColor, "#A2");
1428                         Assert.AreEqual (SystemColors.Highlight, grid.DefaultCellStyle.SelectionBackColor, "#A3");
1429                         Assert.AreEqual (SystemColors.HighlightText, grid.DefaultCellStyle.SelectionForeColor, "#A4");
1430                         Assert.AreSame (grid.Font, grid.DefaultCellStyle.Font, "#A5");
1431                         Assert.AreEqual (DataGridViewContentAlignment.MiddleLeft, grid.DefaultCellStyle.Alignment, "#A6");
1432                         Assert.AreEqual (DataGridViewTriState.False, grid.DefaultCellStyle.WrapMode, "#A7");
1433                 }
1434
1435                 [Test]
1436                 public void MethodIsInputKey ()
1437                 {
1438                         string result = string.Empty;
1439                         string expected = "13;13;33;33;34;34;35;36;37;38;39;40;46;48;96;113;";
1440
1441                         ExposeProtectedProperties dgv = new ExposeProtectedProperties ();
1442                 
1443                         foreach (Keys k in Enum.GetValues (typeof (Keys)))
1444                                 if (dgv.PublicIsInputKey (k))
1445                                         result += ((int)k).ToString () + ";";
1446
1447                         Assert.AreEqual (expected, result, "A1");
1448                 }
1449
1450                 [Test]
1451                 public void MethodIsInputChar ()
1452                 {
1453                         bool result = false;
1454
1455                         ExposeProtectedProperties dgv = new ExposeProtectedProperties ();
1456
1457                         for (int i = 0; i < 255; i++)
1458                                 if (!dgv.PublicIsInputChar ((char)i))
1459                                         result = true;
1460
1461                         // Basically, it always returns true
1462                         Assert.AreEqual (false, result, "A1");
1463                 }
1464
1465                 [Test]
1466                 public void RowsDefaultCellStyle ()
1467                 {
1468                         DataGridView grid = new DataGridView();
1469                         Assert.AreEqual (Color.Empty, grid.RowsDefaultCellStyle.BackColor, "#A1");
1470                         Assert.AreEqual (Color.Empty, grid.RowsDefaultCellStyle.ForeColor, "#A2");
1471                         Assert.AreEqual (Color.Empty, grid.RowsDefaultCellStyle.SelectionBackColor, "#A3");
1472                         Assert.AreEqual (Color.Empty, grid.RowsDefaultCellStyle.SelectionForeColor, "#A4");
1473                         Assert.IsNull(grid.RowsDefaultCellStyle.Font, "#A5");
1474                         Assert.AreEqual (DataGridViewContentAlignment.NotSet, grid.RowsDefaultCellStyle.Alignment, "#A6");
1475                         Assert.AreEqual (DataGridViewTriState.NotSet, grid.RowsDefaultCellStyle.WrapMode, "#A7");
1476                 }
1477
1478                 [Test]
1479                 public void RowHeadersDefaultCellStyle ()
1480                 {
1481                         DataGridView grid = new DataGridView();
1482                         Assert.AreEqual (SystemColors.Control, grid.RowHeadersDefaultCellStyle.BackColor, "#A1");
1483                         Assert.AreEqual (SystemColors.WindowText, grid.RowHeadersDefaultCellStyle.ForeColor, "#A2");
1484                         Assert.AreEqual (SystemColors.Highlight, grid.RowHeadersDefaultCellStyle.SelectionBackColor, "#A3");
1485                         Assert.AreEqual (SystemColors.HighlightText, grid.RowHeadersDefaultCellStyle.SelectionForeColor, "#A4");
1486                         Assert.AreSame (grid.Font, grid.RowHeadersDefaultCellStyle.Font, "#A5");
1487                         Assert.AreEqual (DataGridViewContentAlignment.MiddleLeft, grid.RowHeadersDefaultCellStyle.Alignment, "#A6");
1488                         Assert.AreEqual (DataGridViewTriState.True, grid.RowHeadersDefaultCellStyle.WrapMode, "#A7");
1489                 }
1490
1491                 private class MockDataGridView : DataGridView
1492                 {
1493                         public Size default_size {
1494                                 get { return base.DefaultSize; }
1495                         }
1496                 }
1497
1498                 [Test]
1499                 public void bug_82326 ()
1500                 {
1501                         using (Form f = new Form ()) {
1502                                 DataGridView _dataGrid;
1503                                 DataGridViewTextBoxColumn _column;
1504
1505                                 _dataGrid = new DataGridView ();
1506                                 _column = new DataGridViewTextBoxColumn ();
1507                                 f.SuspendLayout ();
1508                                 ((ISupportInitialize)(_dataGrid)).BeginInit ();
1509                                 // 
1510                                 // _dataGrid
1511                                 // 
1512                                 _dataGrid.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
1513                                 _dataGrid.Columns.Add (_column);
1514                                 _dataGrid.RowTemplate.Height = 21;
1515                                 _dataGrid.Location = new Point (12, 115);
1516                                 _dataGrid.Size = new Size (268, 146);
1517                                 _dataGrid.TabIndex = 0;
1518                                 // 
1519                                 // _column
1520                                 // 
1521                                 _column.HeaderText = "Column";
1522                                 // 
1523                                 // MainForm
1524                                 // 
1525                                 f.ClientSize = new Size (292, 273);
1526                                 f.Controls.Add (_dataGrid);
1527                                 ((ISupportInitialize)(_dataGrid)).EndInit ();
1528                                 f.ResumeLayout (false);
1529                                 f.Load += delegate (object sender, EventArgs e) { ((Control)sender).FindForm ().Close (); };
1530
1531                                 Application.Run (f);
1532                         }
1533                 }
1534                 
1535                 [Test]
1536                 public void RowCountIncrease ()
1537                 {
1538                         DataGridView dgv = new DataGridView ();
1539                         dgv.RowCount = 3;
1540                         
1541                         Assert.AreEqual (3, dgv.RowCount, "A1");
1542                         Assert.AreEqual (1, dgv.ColumnCount, "A2");
1543
1544                         Assert.AreEqual (0, dgv.Rows[0].Index, "A3");
1545                         Assert.AreEqual (1, dgv.Rows[1].Index, "A4");
1546                         Assert.AreEqual (2, dgv.Rows[2].Index, "A5");
1547
1548
1549                         dgv.RowCount = 2;
1550                         
1551                         Assert.AreEqual (2, dgv.RowCount, "B1");
1552                         Assert.AreEqual (1, dgv.ColumnCount, "B2");
1553
1554                         Assert.AreEqual (0, dgv.Rows[0].Index, "B3");
1555                         Assert.AreEqual (1, dgv.Rows[1].Index, "B4");
1556
1557                         dgv.RowCount = 6;
1558                         
1559                         Assert.AreEqual (6, dgv.RowCount, "C1");
1560                         Assert.AreEqual (1, dgv.ColumnCount, "C2");
1561
1562                         Assert.AreEqual (0, dgv.Rows[0].Index, "C3");
1563                         Assert.AreEqual (1, dgv.Rows[1].Index, "C4");
1564                         Assert.AreEqual (2, dgv.Rows[2].Index, "C5");
1565
1566                         dgv.AllowUserToAddRows = false;
1567
1568                         Assert.AreEqual (5, dgv.RowCount, "D1");
1569                         Assert.AreEqual (1, dgv.ColumnCount, "D2");
1570
1571                         dgv.RowCount = 1;
1572                         
1573                         Assert.AreEqual (1, dgv.RowCount, "E1");
1574                         Assert.AreEqual (1, dgv.ColumnCount, "E2");
1575
1576                         Assert.AreEqual (0, dgv.Rows[0].Index, "E3");
1577
1578                         dgv.RowCount = 8;
1579                         
1580                         Assert.AreEqual (8, dgv.RowCount, "F1");
1581                         Assert.AreEqual (1, dgv.ColumnCount, "F2");
1582
1583                         Assert.AreEqual (0, dgv.Rows[0].Index, "F3");
1584                         Assert.AreEqual (1, dgv.Rows[1].Index, "F4");
1585                 }
1586
1587                 [Test]
1588                 public void RowCountDecrease ()
1589                 {
1590                         DataGridView dgv = new DataGridView ();
1591                         dgv.RowCount = 6;
1592                         
1593                         Assert.AreEqual (6, dgv.RowCount, "A1");
1594                         Assert.AreEqual (1, dgv.ColumnCount, "A2");
1595
1596                         dgv.RowCount = 3;
1597                         Assert.AreEqual (3, dgv.RowCount, "A3");
1598                         Assert.AreEqual (0, dgv.Rows[0].Index, "A4");
1599                         Assert.AreEqual (1, dgv.Rows[1].Index, "A5");
1600                         Assert.AreEqual (2, dgv.Rows[2].Index, "A6");
1601
1602                         try {
1603                                 dgv.RowCount = 0;
1604                                 Assert.Fail ("C1");
1605                         } catch {}
1606
1607
1608                         dgv.RowCount = 6;
1609                         
1610                         Assert.AreEqual (6, dgv.RowCount, "B1");
1611                         Assert.AreEqual (1, dgv.ColumnCount, "B2");
1612
1613                         Assert.AreEqual (0, dgv.Rows[0].Index, "B3");
1614                         Assert.AreEqual (1, dgv.Rows[1].Index, "B4");
1615                         Assert.AreEqual (2, dgv.Rows[2].Index, "B5");
1616
1617
1618                         dgv.RowCount = 2;
1619                         
1620                         Assert.AreEqual (2, dgv.RowCount, "C1");
1621                         Assert.AreEqual (1, dgv.ColumnCount, "C2");
1622
1623                         Assert.AreEqual (0, dgv.Rows[0].Index, "C3");
1624                         Assert.AreEqual (1, dgv.Rows[1].Index, "C4");
1625
1626                         dgv.AllowUserToAddRows = false;
1627
1628                         Assert.AreEqual (1, dgv.RowCount, "D1");
1629                         Assert.AreEqual (1, dgv.ColumnCount, "D2");
1630
1631                         Assert.AreEqual (0, dgv.Rows[0].Index, "D3");
1632
1633                         dgv.RowCount = 6;
1634                         
1635                         Assert.AreEqual (6, dgv.RowCount, "E1");
1636                         Assert.AreEqual (1, dgv.ColumnCount, "E2");
1637
1638                         Assert.AreEqual (0, dgv.Rows[0].Index, "E3");
1639                         Assert.AreEqual (1, dgv.Rows[1].Index, "E4");
1640                         Assert.AreEqual (2, dgv.Rows[2].Index, "E5");
1641
1642
1643                         dgv.RowCount = 2;
1644                         
1645                         Assert.AreEqual (2, dgv.RowCount, "F1");
1646                         Assert.AreEqual (1, dgv.ColumnCount, "F2");
1647
1648                         Assert.AreEqual (0, dgv.Rows[0].Index, "F3");
1649                         Assert.AreEqual (1, dgv.Rows[1].Index, "F4");
1650
1651                 }
1652
1653                 [Test]
1654                 public void BindToReadonlyProperty ()
1655                 {
1656                         Form f = new Form ();
1657                         f.ShowInTaskbar = false;
1658                         DataGridView dgv = new DataGridView ();
1659                         
1660                         List<cust> l = new List<cust> ();
1661                         l.Add (new cust ());
1662
1663                         dgv.DataSource = l;
1664                         f.Controls.Add (dgv);
1665                         
1666                         f.Show ();
1667                         
1668                         Assert.AreEqual ("Name", dgv.Columns[0].Name, "A1");
1669                         Assert.AreEqual (true, dgv.Columns[0].ReadOnly, "A2");
1670                         
1671                         f.Close ();
1672                         f.Dispose ();
1673                 }
1674
1675                 class cust { public string Name { get { return "test"; } } }
1676         
1677                 [Test]
1678                 public void EnableHeadersVisualStylesDefaultValue ()
1679                 {
1680                         Assert.AreEqual (true, new DataGridView ().EnableHeadersVisualStyles);
1681                 }
1682
1683                 [Test]
1684                 public void RowTemplate ()
1685                 {
1686                         DataGridView dgv = new DataGridView ();
1687
1688                         Form f = new Form ();
1689                         f.Controls.Add (dgv);
1690                         f.Show ();
1691
1692                         dgv.Columns.Add ("A1", "A1");
1693                         Assert.AreEqual (0, dgv.RowTemplate.Cells.Count, "A1");
1694                         Assert.IsNull (dgv.RowTemplate.DataGridView, "A2");
1695
1696                         dgv.Columns.Add ("A2", "A2");
1697                         Assert.AreEqual (0, dgv.RowTemplate.Cells.Count, "A3");
1698
1699                         dgv.Rows.Add (3, 6);
1700
1701                         dgv.Columns.Remove ("A1");
1702
1703                         Assert.AreEqual (0, dgv.RowTemplate.Cells.Count, "A4");
1704                         Assert.AreEqual (1, dgv.Rows[0].Cells.Count, "A5");
1705
1706                         dgv.Columns.Clear ();
1707
1708                         Assert.AreEqual (0, dgv.RowTemplate.Cells.Count, "A6");
1709                         Assert.AreEqual (0, dgv.Rows.Count, "A7");
1710
1711                         f.Close ();
1712                         f.Dispose ();
1713                 }
1714
1715                 [Test]
1716                 public void ScrollToSelectionSynchronous()
1717                 {
1718                         DataGridView dgv = new DataGridView ();
1719                         dgv.RowCount = 1000;
1720                         dgv.CurrentCell = dgv[0, dgv.RowCount -1];              
1721                         Rectangle rowRect = dgv.GetRowDisplayRectangle (dgv.RowCount - 1, false);
1722                         Assert.AreEqual (true, dgv.DisplayRectangle.Contains (rowRect), "#01");
1723                 }
1724
1725                 [Test]
1726                 public void CurrentCell()
1727                 {
1728                         DataGridView dgv = new DataGridView ();
1729                         dgv.AllowUserToAddRows = false;
1730
1731                         Assert.IsNull (dgv.CurrentCell, "A1");
1732
1733                         dgv.RowCount = 10;
1734                         dgv.ColumnCount = 2;
1735                         Assert.AreEqual (10, dgv.RowCount, "B1");
1736                         Assert.AreEqual (2, dgv.ColumnCount, "B2");
1737                         Assert.IsNull (dgv.CurrentCell, "B3");
1738
1739                         dgv.CurrentCell = dgv[1, 9];
1740                         Assert.IsNotNull (dgv.CurrentCell, "H1");
1741                         Assert.AreEqual (9, dgv.CurrentCell.RowIndex, "H2");
1742                         Assert.AreEqual (1, dgv.CurrentCell.ColumnIndex, "H3");
1743                         
1744                         dgv.CurrentCell = null;
1745                         Assert.IsNull (dgv.CurrentCell, "C1");
1746
1747                         dgv.CurrentCell = dgv[1, 9];
1748                         Assert.IsNotNull (dgv.CurrentCell, "D1");
1749                         Assert.AreEqual (9, dgv.CurrentCell.RowIndex, "D2");
1750                         Assert.AreEqual (1, dgv.CurrentCell.ColumnIndex, "D3");
1751
1752                         dgv.RowCount = 9;
1753                         Assert.IsNotNull (dgv.CurrentCell, "E1");
1754                         Assert.AreEqual (8, dgv.CurrentCell.RowIndex, "E2");
1755                         Assert.AreEqual (1, dgv.CurrentCell.ColumnIndex, "E3");
1756
1757                         dgv.CurrentCell = dgv[0, 4];
1758                         dgv.RowCount = 2;
1759                         Assert.IsNotNull (dgv.CurrentCell, "F1");
1760                         Assert.AreEqual (1, dgv.CurrentCell.RowIndex, "F2");
1761                         Assert.AreEqual (0, dgv.CurrentCell.ColumnIndex, "F3");
1762
1763                         dgv.RowCount = 0;
1764                         Assert.IsNull (dgv.CurrentCell, "G1");
1765
1766                         dgv.RowCount = 10;
1767                         Assert.AreEqual (10, dgv.RowCount, "I1");
1768                         dgv.CurrentCell = dgv[0, 4];
1769                         dgv.ColumnCount = 0;
1770                         Assert.AreEqual (0, dgv.RowCount, "I2");
1771                         Assert.IsNull (dgv.CurrentCell, "I3");
1772
1773                         dgv.RowCount = 0;
1774                         dgv.ColumnCount = 0;
1775                         dgv.CreateControl ();
1776                         dgv.ColumnCount = 2;
1777                         dgv.RowCount = 3;
1778
1779                         Assert.IsNotNull (dgv.CurrentCell, "G1");
1780                         Assert.AreEqual (0, dgv.CurrentCell.RowIndex, "G1");
1781                         Assert.AreEqual (0, dgv.CurrentCell.ColumnIndex, "G1");
1782                 }
1783
1784                 [Test]
1785                 public void DataSourceBindingContextDependency ()
1786                 {
1787                         List<DataItem> dataList = new List<DataItem> ();
1788                         dataList.Add (new DataItem ());
1789                         dataList.Add (new DataItem ());
1790
1791                         DataGridView dgv = new DataGridView ();
1792                         dgv.DataSource = dataList;
1793                         Assert.IsNull (dgv.BindingContext, "#1");
1794                         Assert.IsFalse (dgv.IsHandleCreated, "#2");
1795                         Assert.AreEqual (0, dgv.RowCount, "#3");
1796
1797                         dgv.DataSource = null;
1798
1799                         Form form = new Form ();
1800                         form.Controls.Add (dgv);
1801                         dgv.DataSource = dataList;
1802
1803                         Assert.IsNotNull (dgv.BindingContext, "#4");
1804                         Assert.IsFalse (dgv.IsHandleCreated, "#5");
1805                         Assert.AreEqual (2, dgv.RowCount, "#6");
1806
1807                         dgv.Dispose ();
1808                         dgv = new DataGridView ();
1809                         dgv.DataSource = dataList;
1810
1811                         Assert.IsNull (dgv.BindingContext, "#7");
1812                         Assert.IsFalse (dgv.IsHandleCreated, "#8");
1813                         Assert.AreEqual (0, dgv.RowCount, "#9");
1814
1815                         dgv.CreateControl ();
1816
1817                         Assert.IsNull (dgv.BindingContext, "#10");
1818                         Assert.IsTrue (dgv.IsHandleCreated, "#11");
1819                         Assert.AreEqual (0, dgv.RowCount, "#12");
1820                 }
1821
1822                 [Test]
1823                 public void RowTemplateDataGridView ()
1824                 {
1825                         DataGridView gdv = new DataGridView ();
1826                         Assert.IsNull (gdv.RowTemplate.DataGridView, "#1");
1827                 }
1828         }
1829         
1830         [TestFixture]
1831         public class DataGridViewControlCollectionTest
1832         {
1833                 [Test]
1834                 public void TestClear ()
1835                 {
1836                         using (DataGridView dgv = new DataGridView ()) {
1837                                 DataGridView.DataGridViewControlCollection controls = (DataGridView.DataGridViewControlCollection) dgv.Controls;
1838                                 Control c1 = new Control ();
1839                                 Control c2 = new Control ();
1840                                 Control c3 = new Control ();
1841                                 Assert.AreEqual (2, controls.Count, "#02");
1842                                 controls.Add (c1);
1843                                 controls.Add (c2);
1844                                 controls.Add (c3);
1845                                 Assert.AreEqual (5, controls.Count, "#02");
1846                                 controls.Clear ();
1847                                 Assert.AreEqual (3, controls.Count, "#03");
1848                                 Assert.AreSame (c2, controls [2], "#04");
1849                         }
1850
1851                         // Maybe MS should start writing unit-tests?
1852
1853                         using (DataGridView dgv = new DataGridView ()) {
1854                                 DataGridView.DataGridViewControlCollection controls = (DataGridView.DataGridViewControlCollection)dgv.Controls;
1855                                 Control [] c = new Control [20];
1856                                 for (int i = 0; i < c.Length; i++) {
1857                                         c [i] = new Control ();
1858                                         c [i].Text = "#" + i.ToString ();
1859                                 }
1860                                 
1861                                 Assert.AreEqual (2, controls.Count, "#02");
1862                                 controls.AddRange (c);
1863                                 Assert.AreEqual (22, controls.Count, "#02");
1864                                 controls.Clear ();
1865                                 Assert.AreEqual (12, controls.Count, "#03");
1866                                 
1867                                 for (int i = 0; i < c.Length; i += 2) {
1868                                         Assert.AreSame (c [i+1], controls [ (i / 2) + 2], "#A" + i.ToString ());
1869                                 }
1870                         }
1871                 }
1872
1873                 [Test]
1874                 public void TestCopyTo ()
1875                 {
1876                         using (DataGridView dgv = new DataGridView ()) {
1877                                 DataGridView.DataGridViewControlCollection controls = (DataGridView.DataGridViewControlCollection)dgv.Controls;
1878                                 Control c1 = new Control ();
1879                                 Control c2 = new Control ();
1880                                 Control c3 = new Control ();
1881                                 Control [] copy = new Control [10];
1882                                 Assert.AreEqual (2, controls.Count, "#01");
1883                                 controls.AddRange (new Control [] { c1, c2, c3 });
1884                                 Assert.AreEqual (5, controls.Count, "#01-b");
1885                                 controls.CopyTo (copy, 0);
1886                                 Assert.AreEqual (5, controls.Count, "#02");
1887                                 Assert.AreEqual (10, copy.Length, "#03");
1888                                 for (int i = 0; i < copy.Length; i++) {
1889                                         if (i >= 5)
1890                                                 Assert.IsNull (copy [i], "#A" + i.ToString ());
1891                                         else
1892                                                 Assert.IsNotNull (copy [i], "#B" + i.ToString ());
1893                                 }
1894                         }
1895                 }
1896
1897                 [Test]
1898                 [ExpectedException (typeof (NotSupportedException))]
1899                 public void TestInsert ()
1900                 {
1901                         using (DataGridView dgv = new DataGridView ()) {
1902                                 DataGridView.DataGridViewControlCollection controls = (DataGridView.DataGridViewControlCollection)dgv.Controls;
1903                                 controls.Insert (1, new Control ());
1904                         }
1905                 }
1906
1907                 [Test]
1908                 public void TestRemove ()
1909                 {
1910                         using (DataGridView dgv = new DataGridView ()) {
1911                                 DataGridView.DataGridViewControlCollection controls = (DataGridView.DataGridViewControlCollection)dgv.Controls;
1912                                 Control c1 = new Control ();
1913                                 Control c2 = new Control ();
1914                                 Control c3 = new Control ();
1915                                 Control [] copy = new Control [10];
1916                                 
1917                                 controls.AddRange (new Control [] {c1, c2, c3});
1918                                 
1919                                 controls.Remove (c2);
1920                                 Assert.AreEqual (4, controls.Count, "#01");
1921                                 controls.Remove (c2);
1922                                 Assert.AreEqual (4, controls.Count, "#02");
1923                                 controls.Remove (c1);
1924                                 Assert.AreEqual (3, controls.Count, "#03");
1925                                 controls.Remove (c3);
1926                                 Assert.AreEqual (2, controls.Count, "#04");
1927                                 
1928                                 controls.Remove (controls [0]);
1929                                 controls.Remove (controls [1]);
1930                                 Assert.AreEqual (2, controls.Count, "#05");
1931                         }
1932                 }
1933         }
1934                 
1935 }
1936
1937 #endif