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:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
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.
20 // Copyright (c) 2007 Novell, Inc. (http://www.novell.com)
23 // Rolf Bjarne Kvinge (RKvinge@novell.com)
29 using NUnit.Framework;
32 using System.Windows.Forms;
33 using System.ComponentModel;
34 using System.Collections;
35 using System.Collections.Generic;
37 namespace MonoTests.System.Windows.Forms
39 public static class DataGridViewCommon
42 /// Creates a 2x2 grid.
43 /// <para> A B </para>
44 /// <para>1 A1 B1</para>
45 /// <para>2 A2 B2</para>
47 /// <returns></returns>
48 public static DataGridView CreateAndFill ()
50 DataGridView dgv = new DataGridView ();
51 dgv.Columns.Add ("A", "A");
52 dgv.Columns.Add ("B", "B");
53 dgv.Rows.Add ("Cell A1", "Cell B1");
54 dgv.Rows.Add ("Cell A2", "Cell B2");
59 /// Creates a 2x2 grid, all cells have a GetClipboardContentsPublic method.
60 /// <para> A B </para>
61 /// <para>1 A1 B1</para>
62 /// <para>2 A2 B2</para>
64 /// <returns></returns>
65 public static DataGridView CreateAndFillForClipboard ()
67 DataGridView dgv = new DataGridView ();
68 DataGridViewColumn col;
70 DataGridViewCell cell;
72 foreach (string name in new string [] {"A", "B", "C", "D"}) {
73 col = new DataGridViewColumn ();
74 col.CellTemplate = new DataGridViewTextBoxCell ();
75 col.HeaderCell = new DataGridViewColumnHeaderTest.DataGridViewColumnHeaderClipboardCell ();
77 //if (dgv.Columns.Count == 1) {
78 // col.HeaderText = null;
79 //} else if (dgv.Columns.Count == 2) {
80 // col.HeaderText = string.Empty;
82 col.HeaderText = name;
85 dgv.Columns.Add (col);
88 for (int i = 1; i <= 4; i++) {
89 row = new DataGridViewRow ();
90 row.HeaderCell = new DataGridViewRowHeaderTest.DataGridViewRowHeaderClipboardCell ();
91 //if (i == 3) { // Leave one at default value of null
92 // row.HeaderCell.Value = null;
93 //} else if (i == 2) {
94 // row.HeaderCell.Value = string.Empty;
96 row.HeaderCell.Value = "Row#" + i.ToString ();
99 foreach (DataGridViewColumn c in dgv.Columns) {
100 cell = new DataGridViewCellTest.DataGridViewClipboardCell ();
101 cell.Value = "Cell " + c.Name + i.ToString ();
102 row.Cells.Add (cell);
111 /// Creates a 10x10 grid.
112 /// <para> A B </para>
113 /// <para>1 A1 B1</para>
114 /// <para>2 A2 B2</para>
116 /// <returns></returns>
117 public static DataGridView CreateAndFillBig ()
119 DataGridView dgv = new DataGridView ();
120 for (int c = 0; c < 10; c++) {
121 string A = (((char) ((int) 'A') + c)).ToString ();
122 dgv.Columns.Add (A, A);
124 for (int r = 0; r < 10; r++) {
125 List<object> cells = new List<object> ();
126 for (int c = 0; c < 10; c++) {
127 cells.Add (string.Format ("Cell {0}{1}", dgv.Columns [c].Name, r));
129 dgv.Rows.Add (cells);