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) 2005 Novell, Inc. (http://www.novell.com)
23 // Pedro MartÃnez Juliá <pedromj@gmail.com>
29 using NUnit.Framework;
32 using System.Windows.Forms;
33 using System.Collections;
35 namespace MonoTests.System.Windows.Forms {
38 public class DataGridViewRowTest : TestHelper {
41 public void TestDefaultValues () {
45 [ExpectedException(typeof(InvalidOperationException))]
46 public void TestVisibleInvalidOperationException () {
47 DataGridView grid = new DataGridView();
48 DataGridViewRow row = new DataGridViewRow();
56 DataGridViewRow row = new DataGridViewRow();
57 Assert.IsTrue (row.Height > 5, "#1");
59 Assert.AreEqual (70, row.Height, "#2");
61 Assert.AreEqual (40, row.Height, "#3");
65 [Category ("NotWorking")]
66 public void MinimumHeight ()
68 DataGridViewRow row = new DataGridViewRow();
69 Assert.IsTrue (row.MinimumHeight > 0, "#A1");
70 Assert.IsFalse (row.Height > row.MinimumHeight, "#A2");
71 row.MinimumHeight = 40;
73 Assert.AreEqual (40, row.MinimumHeight, "#B1");
74 Assert.AreEqual (50, row.Height, "#B2");
75 row.MinimumHeight = 20;
76 Assert.AreEqual (20, row.MinimumHeight, "#C1");
77 Assert.AreEqual (20, row.Height, "#C2");
78 row.MinimumHeight = 40;
79 Assert.AreEqual (40, row.MinimumHeight, "#D1");
80 Assert.AreEqual (40, row.Height, "#D2");
87 [NUnit.Framework.Category ("NotWorking")] // DGVComboBox not implemented
88 public void AddRow_Changes ()
91 using (DataGridView dgv = new DataGridView ()) {
92 DataGridViewColumn col = new DataGridViewComboBoxColumn ();
93 DataGridViewRow row = new DataGridViewRow ();
94 DataGridViewCell cell = new DataGridViewComboBoxCell ();
96 Assert.IsNotNull (row.AccessibilityObject, "#A row.AccessibilityObject");
97 Assert.IsNotNull (row.Cells, "#A row.Cells");
98 Assert.IsNull (row.ContextMenuStrip, "#A row.ContextMenuStrip");
99 Assert.IsNull (row.DataBoundItem, "#A row.DataBoundItem");
100 Assert.IsNull (row.DataGridView, "#A row.DataGridView");
101 Assert.IsNotNull (row.DefaultCellStyle, "#A row.DefaultCellStyle");
102 Assert.IsNotNull (row.DefaultHeaderCellType, "#A row.DefaultHeaderCellType");
103 Assert.AreEqual (false, row.Displayed, "#A row.Displayed");
104 Assert.AreEqual (0, row.DividerHeight, "#A row.DividerHeight");
105 Assert.AreEqual (@"", row.ErrorText, "#A row.ErrorText");
106 Assert.AreEqual (false, row.Frozen, "#A row.Frozen");
107 Assert.AreEqual (true, row.HasDefaultCellStyle, "#A row.HasDefaultCellStyle");
108 Assert.IsNotNull (row.HeaderCell, "#A row.HeaderCell");
109 // DPI Dependent? // Assert.AreEqual (22, row.Height, "#A row.Height");
110 Assert.AreEqual (-1, row.Index, "#A row.Index");
112 object zxf = row.InheritedStyle;
113 TestHelper.RemoveWarning (zxf);
114 Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#A row.InheritedStyle");
115 } catch (InvalidOperationException ex) {
116 Assert.AreEqual (@"Getting the InheritedStyle property of a shared row is not a valid operation.", ex.Message);
117 } catch (Exception ex) {
118 Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#A row.InheritedStyle");
120 Assert.AreEqual (false, row.IsNewRow, "#A row.IsNewRow");
121 Assert.AreEqual (3, row.MinimumHeight, "#A row.MinimumHeight");
122 Assert.AreEqual (false, row.ReadOnly, "#A row.ReadOnly");
123 Assert.AreEqual (DataGridViewTriState.NotSet, row.Resizable, "#A row.Resizable");
124 Assert.AreEqual (false, row.Selected, "#A row.Selected");
125 Assert.AreEqual (DataGridViewElementStates.Visible, row.State, "#A row.State");
126 Assert.IsNull (row.Tag, "#A row.Tag");
127 Assert.AreEqual (true, row.Visible, "#A row.Visible");
129 row.Cells.Add (cell);
131 Assert.IsNotNull (row.AccessibilityObject, "#B row.AccessibilityObject");
132 Assert.IsNotNull (row.Cells, "#B row.Cells");
133 Assert.IsNull (row.ContextMenuStrip, "#B row.ContextMenuStrip");
134 Assert.IsNull (row.DataBoundItem, "#B row.DataBoundItem");
135 Assert.IsNull (row.DataGridView, "#B row.DataGridView");
136 Assert.IsNotNull (row.DefaultCellStyle, "#B row.DefaultCellStyle");
137 Assert.IsNotNull (row.DefaultHeaderCellType, "#B row.DefaultHeaderCellType");
138 Assert.AreEqual (false, row.Displayed, "#B row.Displayed");
139 Assert.AreEqual (0, row.DividerHeight, "#B row.DividerHeight");
140 Assert.AreEqual (@"", row.ErrorText, "#B row.ErrorText");
141 Assert.AreEqual (false, row.Frozen, "#B row.Frozen");
142 Assert.AreEqual (true, row.HasDefaultCellStyle, "#B row.HasDefaultCellStyle");
143 Assert.IsNotNull (row.HeaderCell, "#B row.HeaderCell");
144 // DPI Dependent? // Assert.AreEqual (22, row.Height, "#B row.Height");
145 Assert.AreEqual (-1, row.Index, "#B row.Index");
147 object zxf = row.InheritedStyle;
148 TestHelper.RemoveWarning (zxf);
149 Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#B row.InheritedStyle");
150 } catch (InvalidOperationException ex) {
151 Assert.AreEqual (@"Getting the InheritedStyle property of a shared row is not a valid operation.", ex.Message);
152 } catch (Exception ex) {
153 Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#B row.InheritedStyle");
155 Assert.AreEqual (false, row.IsNewRow, "#B row.IsNewRow");
156 Assert.AreEqual (3, row.MinimumHeight, "#B row.MinimumHeight");
157 Assert.AreEqual (false, row.ReadOnly, "#B row.ReadOnly");
158 Assert.AreEqual (DataGridViewTriState.NotSet, row.Resizable, "#B row.Resizable");
159 Assert.AreEqual (false, row.Selected, "#B row.Selected");
160 Assert.AreEqual (DataGridViewElementStates.Visible, row.State, "#B row.State");
161 Assert.IsNull (row.Tag, "#B row.Tag");
162 Assert.AreEqual (true, row.Visible, "#B row.Visible");
164 dgv.Columns.Add (col);
166 Assert.IsNotNull (row.AccessibilityObject, "#C row.AccessibilityObject");
167 Assert.IsNotNull (row.Cells, "#C row.Cells");
168 Assert.IsNull (row.ContextMenuStrip, "#C row.ContextMenuStrip");
169 Assert.IsNull (row.DataBoundItem, "#C row.DataBoundItem");
170 Assert.IsNull (row.DataGridView, "#C row.DataGridView");
171 Assert.IsNotNull (row.DefaultCellStyle, "#C row.DefaultCellStyle");
172 Assert.IsNotNull (row.DefaultHeaderCellType, "#C row.DefaultHeaderCellType");
173 Assert.AreEqual (false, row.Displayed, "#C row.Displayed");
174 Assert.AreEqual (0, row.DividerHeight, "#C row.DividerHeight");
175 Assert.AreEqual (@"", row.ErrorText, "#C row.ErrorText");
176 Assert.AreEqual (false, row.Frozen, "#C row.Frozen");
177 Assert.AreEqual (true, row.HasDefaultCellStyle, "#C row.HasDefaultCellStyle");
178 Assert.IsNotNull (row.HeaderCell, "#C row.HeaderCell");
179 // DPI Dependent? // Assert.AreEqual (22, row.Height, "#C row.Height");
180 Assert.AreEqual (-1, row.Index, "#C row.Index");
182 object zxf = row.InheritedStyle;
183 TestHelper.RemoveWarning (zxf);
184 Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#C row.InheritedStyle");
185 } catch (InvalidOperationException ex) {
186 Assert.AreEqual (@"Getting the InheritedStyle property of a shared row is not a valid operation.", ex.Message);
187 } catch (Exception ex) {
188 Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#C row.InheritedStyle");
190 Assert.AreEqual (false, row.IsNewRow, "#C row.IsNewRow");
191 Assert.AreEqual (3, row.MinimumHeight, "#C row.MinimumHeight");
192 Assert.AreEqual (false, row.ReadOnly, "#C row.ReadOnly");
193 Assert.AreEqual (DataGridViewTriState.NotSet, row.Resizable, "#C row.Resizable");
194 Assert.AreEqual (false, row.Selected, "#C row.Selected");
195 Assert.AreEqual (DataGridViewElementStates.Visible, row.State, "#C row.State");
196 Assert.IsNull (row.Tag, "#C row.Tag");
197 Assert.AreEqual (true, row.Visible, "#C row.Visible");
201 Assert.IsNotNull (row.AccessibilityObject, "#D row.AccessibilityObject");
202 Assert.IsNotNull (row.Cells, "#D row.Cells");
204 object zxf = row.ContextMenuStrip;
205 TestHelper.RemoveWarning (zxf);
206 Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#D row.ContextMenuStrip");
207 } catch (InvalidOperationException ex) {
208 Assert.AreEqual (@"Operation cannot be performed on a shared row.", ex.Message);
209 } catch (Exception ex) {
210 Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#D row.ContextMenuStrip");
212 Assert.IsNull (row.DataBoundItem, "#D row.DataBoundItem");
213 Assert.IsNotNull (row.DataGridView, "#D row.DataGridView");
214 Assert.IsNotNull (row.DefaultCellStyle, "#D row.DefaultCellStyle");
215 Assert.IsNotNull (row.DefaultHeaderCellType, "#D row.DefaultHeaderCellType");
217 object zxf = row.Displayed;
218 TestHelper.RemoveWarning (zxf);
219 Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#D row.Displayed");
220 } catch (InvalidOperationException ex) {
221 Assert.AreEqual (@"Getting the Displayed property of a shared row is not a valid operation.", ex.Message);
222 } catch (Exception ex) {
223 Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#D row.Displayed");
225 Assert.AreEqual (0, row.DividerHeight, "#D row.DividerHeight");
227 object zxf = row.ErrorText;
228 TestHelper.RemoveWarning (zxf);
229 Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#D row.ErrorText");
230 } catch (InvalidOperationException ex) {
231 Assert.AreEqual (@"Operation cannot be performed on a shared row.", ex.Message);
232 } catch (Exception ex) {
233 Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#D row.ErrorText");
236 object zxf = row.Frozen;
237 TestHelper.RemoveWarning (zxf);
238 Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#D row.Frozen");
239 } catch (InvalidOperationException ex) {
240 Assert.AreEqual (@"Getting the Frozen property of a shared row is not a valid operation.", ex.Message);
241 } catch (Exception ex) {
242 Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#D row.Frozen");
244 Assert.AreEqual (true, row.HasDefaultCellStyle, "#D row.HasDefaultCellStyle");
245 Assert.IsNotNull (row.HeaderCell, "#D row.HeaderCell");
246 // DPI Dependent? // Assert.AreEqual (22, row.Height, "#D row.Height");
247 Assert.AreEqual (-1, row.Index, "#D row.Index");
249 object zxf = row.InheritedStyle;
250 TestHelper.RemoveWarning (zxf);
251 Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#D row.InheritedStyle");
252 } catch (InvalidOperationException ex) {
253 Assert.AreEqual (@"Getting the InheritedStyle property of a shared row is not a valid operation.", ex.Message);
254 } catch (Exception ex) {
255 Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#D row.InheritedStyle");
257 Assert.AreEqual (false, row.IsNewRow, "#D row.IsNewRow");
258 Assert.AreEqual (3, row.MinimumHeight, "#D row.MinimumHeight");
260 object zxf = row.ReadOnly;
261 TestHelper.RemoveWarning (zxf);
262 Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#D row.ReadOnly");
263 } catch (InvalidOperationException ex) {
264 Assert.AreEqual (@"Getting the ReadOnly property of a shared row is not a valid operation.", ex.Message);
265 } catch (Exception ex) {
266 Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#D row.ReadOnly");
269 object zxf = row.Resizable;
270 TestHelper.RemoveWarning (zxf);
271 Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#D row.Resizable");
272 } catch (InvalidOperationException ex) {
273 Assert.AreEqual (@"Getting the Resizable property of a shared row is not a valid operation.", ex.Message);
274 } catch (Exception ex) {
275 Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#D row.Resizable");
278 object zxf = row.Selected;
279 TestHelper.RemoveWarning (zxf);
280 Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#D row.Selected");
281 } catch (InvalidOperationException ex) {
282 Assert.AreEqual (@"Getting the Selected property of a shared row is not a valid operation.", ex.Message);
283 } catch (Exception ex) {
284 Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#D row.Selected");
287 object zxf = row.State;
288 TestHelper.RemoveWarning (zxf);
289 Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#D row.State");
290 } catch (InvalidOperationException ex) {
291 Assert.AreEqual (@"Getting the State property of a shared row is not a valid operation.", ex.Message);
292 } catch (Exception ex) {
293 Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#D row.State");
295 Assert.IsNull (row.Tag, "#D row.Tag");
297 object zxf = row.Visible;
298 TestHelper.RemoveWarning (zxf);
299 Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#D row.Visible");
300 } catch (InvalidOperationException ex) {
301 Assert.AreEqual (@"Getting the Visible property of a shared row is not a valid operation.", ex.Message);
302 } catch (Exception ex) {
303 Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#D row.Visible");
309 public void InitialValues ()
311 DataGridViewRow row = new DataGridViewRow ();
313 Assert.IsNotNull (row.AccessibilityObject, "#A row.AccessibilityObject");
314 Assert.IsNotNull (row.Cells, "#A row.Cells");
315 Assert.IsNull (row.ContextMenuStrip, "#A row.ContextMenuStrip");
316 Assert.IsNull (row.DataBoundItem, "#A row.DataBoundItem");
317 Assert.IsNull (row.DataGridView, "#A row.DataGridView");
318 Assert.IsNotNull (row.DefaultCellStyle, "#A row.DefaultCellStyle");
319 Assert.IsNotNull (row.DefaultHeaderCellType, "#A row.DefaultHeaderCellType");
320 Assert.AreEqual (false, row.Displayed, "#A row.Displayed");
321 Assert.AreEqual (0, row.DividerHeight, "#A row.DividerHeight");
322 Assert.AreEqual (@"", row.ErrorText, "#A row.ErrorText");
323 Assert.AreEqual (false, row.Frozen, "#A row.Frozen");
324 Assert.AreEqual (true, row.HasDefaultCellStyle, "#A row.HasDefaultCellStyle");
325 Assert.IsNotNull (row.HeaderCell, "#A row.HeaderCell");
326 // DPI Dependent? // Assert.AreEqual (22, row.Height, "#A row.Height");
327 Assert.AreEqual (-1, row.Index, "#A row.Index");
329 object zxf = row.InheritedStyle;
330 TestHelper.RemoveWarning (zxf);
331 Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#A row.InheritedStyle");
332 } catch (InvalidOperationException ex) {
333 Assert.AreEqual (@"Getting the InheritedStyle property of a shared row is not a valid operation.", ex.Message);
334 } catch (Exception ex) {
335 Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#A row.InheritedStyle");
337 Assert.AreEqual (false, row.IsNewRow, "#A row.IsNewRow");
338 Assert.AreEqual (3, row.MinimumHeight, "#A row.MinimumHeight");
339 Assert.AreEqual (false, row.ReadOnly, "#A row.ReadOnly");
340 Assert.AreEqual (DataGridViewTriState.NotSet, row.Resizable, "#A row.Resizable");
341 Assert.AreEqual (false, row.Selected, "#A row.Selected");
342 Assert.AreEqual (DataGridViewElementStates.Visible, row.State, "#A row.State");
343 Assert.IsNull (row.Tag, "#A row.Tag");
344 Assert.AreEqual (true, row.Visible, "#A row.Visible");
350 DataGridView dgv = new DataGridView ();
352 dgv.Columns.Add ("Column 1", "Column 1");
353 dgv.Columns.Add ("Column 2", "Column 2");
355 dgv.Rows.Add ("Cell 1", "Cell 2");
357 DataGridViewRow row1 = dgv.Rows[0];
359 row1.ErrorText = "Yikes!";
361 row1.ReadOnly = true;
362 row1.Visible = false;
364 DataGridViewRow row2 = (DataGridViewRow)row1.Clone ();
366 Assert.AreEqual (2, row2.Cells.Count, "A1");
367 Assert.AreEqual (null, row2.DataGridView, "A3");
368 Assert.AreEqual ("Yikes!", row2.ErrorText, "A4");
369 Assert.AreEqual (-1, row2.HeaderCell.RowIndex, "A5");
370 Assert.AreEqual (-1, row2.Index, "A6");
371 Assert.AreEqual (true, row2.ReadOnly, "A7");
372 Assert.AreEqual ("Helo", row2.Tag, "A8");
373 Assert.AreEqual (false, row2.Visible, "A9");