PageRenderTime 41ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/DataGridViewCommon.cs

https://bitbucket.org/danipen/mono
C# | 135 lines | 67 code | 11 blank | 57 comment | 4 complexity | 84e11335b4cb30e5be77a57c7356ac6c MD5 | raw file
Possible License(s): Unlicense, Apache-2.0, LGPL-2.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0
  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) 2007 Novell, Inc. (http://www.novell.com)
  21. //
  22. // Author:
  23. // Rolf Bjarne Kvinge (RKvinge@novell.com)
  24. //
  25. #if NET_2_0
  26. using NUnit.Framework;
  27. using System;
  28. using System.Drawing;
  29. using System.Windows.Forms;
  30. using System.ComponentModel;
  31. using System.Collections;
  32. using System.Collections.Generic;
  33. namespace MonoTests.System.Windows.Forms
  34. {
  35. public static class DataGridViewCommon
  36. {
  37. /// <summary>
  38. /// Creates a 2x2 grid.
  39. /// <para> A B </para>
  40. /// <para>1 A1 B1</para>
  41. /// <para>2 A2 B2</para>
  42. /// </summary>
  43. /// <returns></returns>
  44. public static DataGridView CreateAndFill ()
  45. {
  46. DataGridView dgv = new DataGridView ();
  47. dgv.Columns.Add ("A", "A");
  48. dgv.Columns.Add ("B", "B");
  49. dgv.Rows.Add ("Cell A1", "Cell B1");
  50. dgv.Rows.Add ("Cell A2", "Cell B2");
  51. return dgv;
  52. }
  53. /// <summary>
  54. /// Creates a 2x2 grid, all cells have a GetClipboardContentsPublic method.
  55. /// <para> A B </para>
  56. /// <para>1 A1 B1</para>
  57. /// <para>2 A2 B2</para>
  58. /// </summary>
  59. /// <returns></returns>
  60. public static DataGridView CreateAndFillForClipboard ()
  61. {
  62. DataGridView dgv = new DataGridView ();
  63. DataGridViewColumn col;
  64. DataGridViewRow row;
  65. DataGridViewCell cell;
  66. foreach (string name in new string [] {"A", "B", "C", "D"}) {
  67. col = new DataGridViewColumn ();
  68. col.CellTemplate = new DataGridViewTextBoxCell ();
  69. col.HeaderCell = new DataGridViewColumnHeaderTest.DataGridViewColumnHeaderClipboardCell ();
  70. col.Name = name;
  71. //if (dgv.Columns.Count == 1) {
  72. // col.HeaderText = null;
  73. //} else if (dgv.Columns.Count == 2) {
  74. // col.HeaderText = string.Empty;
  75. //} else {
  76. col.HeaderText = name;
  77. //}
  78. dgv.Columns.Add (col);
  79. }
  80. for (int i = 1; i <= 4; i++) {
  81. row = new DataGridViewRow ();
  82. row.HeaderCell = new DataGridViewRowHeaderTest.DataGridViewRowHeaderClipboardCell ();
  83. //if (i == 3) { // Leave one at default value of null
  84. // row.HeaderCell.Value = null;
  85. //} else if (i == 2) {
  86. // row.HeaderCell.Value = string.Empty;
  87. //} else {
  88. row.HeaderCell.Value = "Row#" + i.ToString ();
  89. //}
  90. foreach (DataGridViewColumn c in dgv.Columns) {
  91. cell = new DataGridViewCellTest.DataGridViewClipboardCell ();
  92. cell.Value = "Cell " + c.Name + i.ToString ();
  93. row.Cells.Add (cell);
  94. }
  95. dgv.Rows.Add (row);
  96. }
  97. return dgv;
  98. }
  99. /// <summary>
  100. /// Creates a 10x10 grid.
  101. /// <para> A B </para>
  102. /// <para>1 A1 B1</para>
  103. /// <para>2 A2 B2</para>
  104. /// </summary>
  105. /// <returns></returns>
  106. public static DataGridView CreateAndFillBig ()
  107. {
  108. DataGridView dgv = new DataGridView ();
  109. for (int c = 0; c < 10; c++) {
  110. string A = (((char) ((int) 'A') + c)).ToString ();
  111. dgv.Columns.Add (A, A);
  112. }
  113. for (int r = 0; r < 10; r++) {
  114. List<object> cells = new List<object> ();
  115. for (int c = 0; c < 10; c++) {
  116. cells.Add (string.Format ("Cell {0}{1}", dgv.Columns [c].Name, r));
  117. }
  118. dgv.Rows.Add (cells);
  119. }
  120. return dgv;
  121. }
  122. }
  123. }
  124. #endif