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)
28 using NUnit.Framework;
31 using System.Windows.Forms;
32 using System.ComponentModel;
33 using System.Collections;
34 using System.Collections.Generic;
36 namespace MonoTests.System.Windows.Forms
38 public static class DataGridViewCommon
41 /// Creates a 2x2 grid.
42 /// <para> A B </para>
43 /// <para>1 A1 B1</para>
44 /// <para>2 A2 B2</para>
46 /// <returns></returns>
47 public static DataGridView CreateAndFill ()
49 DataGridView dgv = new DataGridView ();
50 dgv.Columns.Add ("A", "A");
51 dgv.Columns.Add ("B", "B");
52 dgv.Rows.Add ("Cell A1", "Cell B1");
53 dgv.Rows.Add ("Cell A2", "Cell B2");
58 /// Creates a 2x2 grid, all cells have a GetClipboardContentsPublic method.
59 /// <para> A B </para>
60 /// <para>1 A1 B1</para>
61 /// <para>2 A2 B2</para>
63 /// <returns></returns>
64 public static DataGridView CreateAndFillForClipboard ()
66 DataGridView dgv = new DataGridView ();
67 DataGridViewColumn col;
69 DataGridViewCell cell;
71 foreach (string name in new string [] {"A", "B", "C", "D"}) {
72 col = new DataGridViewColumn ();
73 col.CellTemplate = new DataGridViewTextBoxCell ();
74 col.HeaderCell = new DataGridViewColumnHeaderTest.DataGridViewColumnHeaderClipboardCell ();
76 //if (dgv.Columns.Count == 1) {
77 // col.HeaderText = null;
78 //} else if (dgv.Columns.Count == 2) {
79 // col.HeaderText = string.Empty;
81 col.HeaderText = name;
84 dgv.Columns.Add (col);
87 for (int i = 1; i <= 4; i++) {
88 row = new DataGridViewRow ();
89 row.HeaderCell = new DataGridViewRowHeaderTest.DataGridViewRowHeaderClipboardCell ();
90 //if (i == 3) { // Leave one at default value of null
91 // row.HeaderCell.Value = null;
92 //} else if (i == 2) {
93 // row.HeaderCell.Value = string.Empty;
95 row.HeaderCell.Value = "Row#" + i.ToString ();
98 foreach (DataGridViewColumn c in dgv.Columns) {
99 cell = new DataGridViewCellTest.DataGridViewClipboardCell ();
100 cell.Value = "Cell " + c.Name + i.ToString ();
101 row.Cells.Add (cell);
110 /// Creates a 10x10 grid.
111 /// <para> A B </para>
112 /// <para>1 A1 B1</para>
113 /// <para>2 A2 B2</para>
115 /// <returns></returns>
116 public static DataGridView CreateAndFillBig ()
118 DataGridView dgv = new DataGridView ();
119 for (int c = 0; c < 10; c++) {
120 string A = (((char) ((int) 'A') + c)).ToString ();
121 dgv.Columns.Add (A, A);
123 for (int r = 0; r < 10; r++) {
124 List<object> cells = new List<object> ();
125 for (int c = 0; c < 10; c++) {
126 cells.Add (string.Format ("Cell {0}{1}", dgv.Columns [c].Name, r));
128 dgv.Rows.Add (cells);