2 // DataGridViewCheckBoxCellTest.cs - Unit tests for
3 // System.Windows.Forms.DataGridViewCheckBoxCellTest
6 // Gert Driesen <drieseng@users.sourceforge.net>
8 // Copyright (C) 2007 Gert Driesen
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Windows.Forms;
35 using NUnit.Framework;
37 using System.Threading;
38 using System.ComponentModel;
40 namespace MonoTests.System.Windows.Forms
43 public class DataGridViewCheckBoxCellTest : TestHelper
46 public void Defaults ()
48 DataGridViewCheckBoxCell cell = new DataGridViewCheckBoxCell ();
50 Assert.AreEqual (null, cell.EditedFormattedValue, "A1");
51 Assert.AreEqual (false, cell.EditingCellValueChanged, "A2");
52 Assert.AreEqual (null, cell.EditType, "A3");
53 Assert.AreEqual (null, cell.FalseValue, "A4");
54 Assert.AreEqual (typeof (bool), cell.FormattedValueType, "A5");
55 Assert.AreEqual (null, cell.IndeterminateValue, "A6");
56 Assert.AreEqual (false, cell.ThreeState, "A7");
57 Assert.AreEqual (null, cell.TrueValue, "A8");
58 Assert.AreEqual (typeof (bool), cell.ValueType, "A9");
60 Assert.AreEqual ("DataGridViewCheckBoxCell { ColumnIndex=-1, RowIndex=-1 }", cell.ToString (), "A10");
62 cell.ThreeState = true;
64 Assert.AreEqual (null, cell.EditedFormattedValue, "A11");
65 Assert.AreEqual (false, cell.EditingCellValueChanged, "A12");
66 Assert.AreEqual (null, cell.EditType, "A13");
67 Assert.AreEqual (null, cell.FalseValue, "A14");
68 Assert.AreEqual (typeof (CheckState), cell.FormattedValueType, "A15");
69 Assert.AreEqual (null, cell.IndeterminateValue, "A16");
70 Assert.AreEqual (true, cell.ThreeState, "A17");
71 Assert.AreEqual (null, cell.TrueValue, "A18");
72 Assert.AreEqual (typeof (CheckState), cell.ValueType, "A19");
78 DataGridViewCheckBoxCell tbc = new DataGridViewCheckBoxCell ();
79 Assert.IsNull (tbc.Value, "#1");
80 tbc.Value = string.Empty;
81 Assert.AreEqual (string.Empty, tbc.Value, "#2");
83 Assert.AreEqual (5, tbc.Value, "#3");
85 Assert.IsNull (tbc.Value, "#4");
89 public void ColumnIndex ()
91 DataGridViewCell c = new BaseCell ();
92 Assert.AreEqual (-1, c.ColumnIndex, "A1");
94 DataGridView dgv = new DataGridView ();
95 dgv.Columns.Add ("hi", "there");
97 DataGridViewRow row = new DataGridViewRow ();
101 Assert.AreEqual (0, dgv.Rows[0].Cells[0].ColumnIndex, "A2");
104 /* font measurement dependent
106 public void ContentBounds ()
108 DataGridViewCell c = new BaseCell ();
109 Assert.AreEqual (Rectangle.Empty, c.ContentBounds, "A1");
111 DataGridView dgv = new DataGridView ();
112 dgv.Columns.Add ("hi", "there");
114 DataGridViewRow row = new DataGridViewRow ();
118 Assert.AreEqual (new Rectangle (2, 4, 13, 13), dgv.Rows[0].Cells[0].ContentBounds, "A2");
123 public void ContextMenuStrip ()
125 DataGridViewCell c = new BaseCell ();
126 Assert.AreEqual (null, c.ContextMenuStrip, "A1");
128 DataGridView dgv = new DataGridView ();
129 dgv.Columns.Add ("hi", "there");
131 DataGridViewRow row = new DataGridViewRow ();
135 ContextMenuStrip cms1 = new ContextMenuStrip ();
136 cms1.Items.Add ("hey");
138 ContextMenuStrip cms2 = new ContextMenuStrip ();
139 cms2.Items.Add ("yo");
141 dgv.Rows[0].ContextMenuStrip = cms1;
142 Assert.AreEqual (null, dgv.Rows[0].Cells[0].ContextMenuStrip, "A2");
144 dgv.Rows[0].Cells[0].ContextMenuStrip = cms2;
145 Assert.AreSame (cms2, dgv.Rows[0].Cells[0].ContextMenuStrip, "A3");
149 public void DataGridView ()
151 DataGridViewCell c = new BaseCell ();
152 Assert.AreEqual (null, c.DataGridView, "A1");
154 DataGridView dgv = new DataGridView ();
155 dgv.Columns.Add ("hi", "there");
157 DataGridViewRow row = new DataGridViewRow ();
161 Assert.AreSame (dgv, dgv.Rows[0].Cells[0].DataGridView, "A2");
165 public void DefaultNewRowValue ()
167 DataGridViewCell c = new BaseCell ();
168 Assert.AreEqual (null, c.DefaultNewRowValue, "A1");
170 DataGridView dgv = new DataGridView ();
171 dgv.Columns.Add ("hi", "there");
173 DataGridViewRow row = new DataGridViewRow ();
177 Assert.AreEqual (null, dgv.Rows[0].Cells[0].DefaultNewRowValue, "A2");
181 public void Displayed ()
183 DataGridViewCell c = new BaseCell ();
184 Assert.AreEqual (false, c.Displayed, "A1");
186 DataGridView dgv = new DataGridView ();
187 dgv.Columns.Add ("hi", "there");
189 DataGridViewRow row = new DataGridViewRow ();
193 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Displayed, "A2");
197 public void EditedFormattedValue ()
199 DataGridViewCell c = new BaseCell ();
200 Assert.AreEqual (null, c.EditedFormattedValue, "A1");
204 public void FormattedValueType ()
206 BaseCell c = new BaseCell ();
207 Assert.AreEqual (typeof (bool), c.FormattedValueType, "A1");
210 Assert.AreEqual (typeof (CheckState), c.FormattedValueType, "A2");
214 public void Frozen ()
216 DataGridViewCell c = new BaseCell ();
217 Assert.AreEqual (false, c.Frozen, "A1");
219 DataGridView dgv = new DataGridView ();
220 dgv.Columns.Add ("hi", "there");
222 DataGridViewRow row = new DataGridViewRow ();
226 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Frozen, "A2");
228 dgv.Columns[0].Frozen = true;
229 dgv.Rows[0].Frozen = true;
230 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Frozen, "A3");
234 public void HasStyle ()
236 DataGridViewCell c = new BaseCell ();
237 Assert.AreEqual (false, c.HasStyle, "A1");
239 DataGridView dgv = new DataGridView ();
240 dgv.Columns.Add ("hi", "there");
242 DataGridViewRow row = new DataGridViewRow ();
246 Assert.AreEqual (false, dgv.Rows[0].Cells[0].HasStyle, "A2");
248 dgv.Rows[0].Cells[0].Style.BackColor = Color.Orange;
249 Assert.AreEqual (true, dgv.Rows[0].Cells[0].HasStyle, "A3");
253 public void InheritedState ()
255 DataGridViewCell c = new BaseCell ();
256 Assert.AreEqual (DataGridViewElementStates.ResizableSet, c.InheritedState, "A1");
258 DataGridView dgv = new DataGridView ();
259 dgv.Columns.Add ("hi", "there");
261 DataGridViewRow row = new DataGridViewRow ();
265 Assert.AreEqual (DataGridViewElementStates.ResizableSet | DataGridViewElementStates.Resizable | DataGridViewElementStates.Visible, dgv.Rows[0].Cells[0].InheritedState, "A2");
267 dgv.Rows[0].Selected = true;
268 Assert.AreEqual (DataGridViewElementStates.Selected | DataGridViewElementStates.ResizableSet | DataGridViewElementStates.Resizable | DataGridViewElementStates.Visible, dgv.Rows[0].Cells[0].InheritedState, "A3");
270 dgv.Rows[0].Selected = false;
271 dgv.Columns[0].Selected = true;
272 Assert.AreEqual (DataGridViewElementStates.ResizableSet | DataGridViewElementStates.Resizable | DataGridViewElementStates.Visible, dgv.Rows[0].Cells[0].InheritedState, "A4");
276 public void InheritedStyle ()
278 DataGridViewCell c = new BaseCell ();
279 DataGridView dgv = new DataGridView ();
280 dgv.Columns.Add ("hi", "there");
282 DataGridViewRow row = new DataGridViewRow ();
286 Assert.AreEqual (SystemColors.Window, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A1");
288 dgv.DefaultCellStyle.BackColor = Color.Firebrick;
289 Assert.AreEqual (Color.Firebrick, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A2");
291 dgv.Columns[0].DefaultCellStyle.BackColor = Color.FloralWhite;
292 Assert.AreEqual (Color.FloralWhite, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A3");
294 dgv.RowsDefaultCellStyle.BackColor = Color.DeepPink;
295 Assert.AreEqual (Color.DeepPink, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A4");
297 dgv.Rows[0].DefaultCellStyle.BackColor = Color.DeepSkyBlue;
298 Assert.AreEqual (Color.DeepSkyBlue, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A5");
300 dgv.Rows[0].Cells[0].Style.BackColor = Color.DodgerBlue;
301 Assert.AreEqual (Color.DodgerBlue, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A6");
305 public void IsInEditMode ()
307 DataGridViewCell c = new BaseCell ();
308 Assert.AreEqual (false, c.IsInEditMode, "A1");
310 DataGridView dgv = new DataGridView ();
311 dgv.Columns.Add ("hi", "there");
313 DataGridViewRow row = new DataGridViewRow ();
317 Assert.AreEqual (false, dgv.Rows[0].Cells[0].IsInEditMode, "A2");
321 public void OwningColumn ()
323 DataGridViewCell c = new BaseCell ();
324 Assert.AreEqual (null, c.OwningColumn, "A1");
326 DataGridView dgv = new DataGridView ();
327 dgv.Columns.Add ("hi", "there");
329 DataGridViewRow row = new DataGridViewRow ();
333 Assert.AreSame (dgv.Columns[0], dgv.Rows[0].Cells[0].OwningColumn, "A2");
337 public void OwningRow ()
339 DataGridViewCell c = new BaseCell ();
340 Assert.AreEqual (null, c.OwningRow, "A1");
342 DataGridView dgv = new DataGridView ();
343 dgv.Columns.Add ("hi", "there");
345 DataGridViewRow row = new DataGridViewRow ();
349 Assert.AreSame (dgv.Rows[0], dgv.Rows[0].Cells[0].OwningRow, "A2");
352 /* Font measurement dependent *
354 public void PreferredSize ()
356 BaseCell c = new BaseCell ();
357 Assert.AreEqual (new Size (-1, -1), c.PreferredSize, "A1");
359 DataGridView dgv = new DataGridView ();
360 dgv.Columns.Add ("hi", "there");
362 DataGridViewRow row = new DataGridViewRow ();
366 Assert.AreEqual (new Size (21, 20), dgv.Rows[0].Cells[0].PreferredSize, "A2");
368 dgv.Rows[0].Cells[0].Value = "bob";
369 Assert.AreEqual (new Size (21, 20), dgv.Rows[0].Cells[0].PreferredSize, "A3");
371 dgv.Rows[0].Cells[0].Value = "roasted quail";
372 Assert.AreEqual (new Size (21, 20), dgv.Rows[0].Cells[0].PreferredSize, "A3");
377 public void ReadOnly ()
379 DataGridViewCell c = new BaseCell ();
380 Assert.AreEqual (false, c.ReadOnly, "A1");
382 DataGridView dgv = new DataGridView ();
383 dgv.Columns.Add ("hi", "there");
385 DataGridViewRow row = new DataGridViewRow ();
389 Assert.AreEqual (false, dgv.Rows[0].Cells[0].ReadOnly, "A2");
391 dgv.Rows[0].ReadOnly = true;
392 Assert.AreEqual (true, dgv.Rows[0].Cells[0].ReadOnly, "A3");
394 dgv.Rows[0].Cells[0].ReadOnly = false;
395 Assert.AreEqual (false, dgv.Rows[0].Cells[0].ReadOnly, "A4");
399 public void Resizable ()
401 DataGridViewCell c = new BaseCell ();
402 Assert.AreEqual (false, c.Resizable, "A1");
404 DataGridView dgv = new DataGridView ();
405 dgv.Columns.Add ("hi", "there");
407 DataGridViewRow row = new DataGridViewRow ();
411 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Resizable, "A2");
413 dgv.Rows[0].Resizable = DataGridViewTriState.False;
414 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Resizable, "A3");
416 dgv.Columns[0].Resizable = DataGridViewTriState.False;
417 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Resizable, "A4");
419 dgv.Columns[0].Resizable = DataGridViewTriState.True;
420 dgv.Rows[0].Resizable = DataGridViewTriState.True;
421 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Resizable, "A5");
423 dgv.AllowUserToResizeColumns = false;
424 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Resizable, "A6");
426 dgv.AllowUserToResizeRows = false;
427 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Resizable, "A7");
429 dgv.Columns[0].Resizable = DataGridViewTriState.NotSet;
430 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Resizable, "A8");
432 dgv.Rows[0].Resizable = DataGridViewTriState.NotSet;
433 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Resizable, "A9");
437 public void RowIndex ()
439 DataGridViewCell c = new BaseCell ();
440 Assert.AreEqual (-1, c.RowIndex, "A1");
442 DataGridView dgv = new DataGridView ();
443 dgv.Columns.Add ("hi", "there");
445 DataGridViewRow row = new DataGridViewRow ();
449 Assert.AreEqual (0, dgv.Rows[0].Cells[0].RowIndex, "A2");
453 public void Selected ()
455 DataGridViewCell c = new BaseCell ();
456 Assert.AreEqual (false, c.Selected, "A1");
458 DataGridView dgv = new DataGridView ();
459 dgv.Columns.Add ("hi", "there");
461 DataGridViewRow row = new DataGridViewRow ();
465 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Selected, "A2");
467 dgv.Columns[0].Selected = true;
468 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Selected, "A3");
470 dgv.Rows[0].Selected = true;
471 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Selected, "A4");
473 dgv.Rows[0].Cells[0].Selected = false;
474 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Selected, "A5");
476 dgv.Rows[0].Selected = false;
477 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Selected, "A6");
479 dgv.Rows[0].Cells[0].Selected = true;
480 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Selected, "A7");
483 /* The height of a cell (row) is based on Font
487 DataGridViewCell c = new BaseCell ();
488 Assert.AreEqual (new Size (-1, -1), c.Size, "A1");
490 DataGridView dgv = new DataGridView ();
491 dgv.Columns.Add ("hi", "there");
493 DataGridViewRow row = new DataGridViewRow ();
497 Assert.AreEqual (new Size (100, 22), dgv.Rows[0].Cells[0].Size, "A2");
499 // Does not resize to content
500 dgv.Rows[0].Cells[0].Value = "bob";
501 Assert.AreEqual (new Size (100, 22), dgv.Rows[0].Cells[0].Size, "A3");
508 DataGridViewCell c = new BaseCell ();
509 Assert.AreEqual (DataGridViewContentAlignment.NotSet, c.Style.Alignment, "A1");
510 Assert.AreEqual (Color.Empty, c.Style.BackColor, "A2");
511 Assert.AreEqual (DBNull.Value, c.Style.DataSourceNullValue, "A3");
512 Assert.AreEqual (null, c.Style.Font, "A4");
513 Assert.AreEqual (Color.Empty, c.Style.ForeColor, "A5");
514 Assert.AreEqual (string.Empty, c.Style.Format, "A6");
515 Assert.AreEqual (Thread.CurrentThread.CurrentCulture, c.Style.FormatProvider, "A7");
516 Assert.AreEqual (true, c.Style.IsDataSourceNullValueDefault, "A8");
517 Assert.AreEqual (true, c.Style.IsFormatProviderDefault, "A9");
518 Assert.AreEqual (true, c.Style.IsNullValueDefault, "A10");
519 Assert.AreEqual (string.Empty, c.Style.NullValue, "A11");
520 Assert.AreEqual (Padding.Empty, c.Style.Padding, "A12");
521 Assert.AreEqual (Color.Empty, c.Style.SelectionBackColor, "A13");
522 Assert.AreEqual (Color.Empty, c.Style.SelectionForeColor, "A14");
523 Assert.AreEqual (null, c.Style.Tag, "A15");
524 Assert.AreEqual (DataGridViewTriState.NotSet, c.Style.WrapMode, "A16");
526 DataGridView dgv = new DataGridView ();
527 dgv.Columns.Add ("hi", "there");
529 DataGridViewRow row = new DataGridViewRow ();
533 // Style does not change based on parent
534 // (InheritedStyle does)
535 Assert.AreEqual (DataGridViewContentAlignment.NotSet, c.Style.Alignment, "A17");
536 Assert.AreEqual (Color.Empty, c.Style.BackColor, "A18");
537 Assert.AreEqual (DBNull.Value, c.Style.DataSourceNullValue, "A19");
538 Assert.AreEqual (null, c.Style.Font, "A20");
539 Assert.AreEqual (Color.Empty, c.Style.ForeColor, "A21");
540 Assert.AreEqual (string.Empty, c.Style.Format, "A22");
541 Assert.AreEqual (Thread.CurrentThread.CurrentCulture, c.Style.FormatProvider, "A23");
542 Assert.AreEqual (true, c.Style.IsDataSourceNullValueDefault, "A24");
543 Assert.AreEqual (true, c.Style.IsFormatProviderDefault, "A25");
544 Assert.AreEqual (true, c.Style.IsNullValueDefault, "A26");
545 Assert.AreEqual (string.Empty, c.Style.NullValue, "A27");
546 Assert.AreEqual (Padding.Empty, c.Style.Padding, "A28");
547 Assert.AreEqual (Color.Empty, c.Style.SelectionBackColor, "A29");
548 Assert.AreEqual (Color.Empty, c.Style.SelectionForeColor, "A30");
549 Assert.AreEqual (null, c.Style.Tag, "A31");
550 Assert.AreEqual (DataGridViewTriState.NotSet, c.Style.WrapMode, "A32");
556 DataGridViewCell c = new BaseCell ();
557 Assert.AreEqual (null, c.Tag, "A1");
559 DataGridView dgv = new DataGridView ();
560 dgv.Columns.Add ("hi", "there");
562 DataGridViewRow row = new DataGridViewRow ();
566 Assert.AreEqual (null, dgv.Rows[0].Cells[0].Tag, "A2");
568 dgv.Rows[0].Cells[0].Tag = "bob";
569 Assert.AreEqual ("bob", dgv.Rows[0].Cells[0].Tag, "A3");
573 public void ToolTipText ()
575 DataGridViewCell c = new BaseCell ();
576 Assert.AreEqual (string.Empty, c.ToolTipText, "A1");
578 DataGridView dgv = new DataGridView ();
579 dgv.Columns.Add ("hi", "there");
581 DataGridViewRow row = new DataGridViewRow ();
585 Assert.AreEqual (string.Empty, dgv.Rows[0].Cells[0].ToolTipText, "A2");
587 dgv.Rows[0].Cells[0].ToolTipText = "bob";
588 Assert.AreEqual ("bob", dgv.Rows[0].Cells[0].ToolTipText, "A3");
592 public void Value2 ()
594 DataGridViewCell c = new BaseCell ();
595 Assert.AreEqual (null, c.Value, "A1");
597 DataGridView dgv = new DataGridView ();
598 dgv.Columns.Add ("hi", "there");
600 DataGridViewRow row = new DataGridViewRow ();
604 Assert.AreEqual (null, dgv.Rows[0].Cells[0].Value, "A2");
606 dgv.Rows[0].Cells[0].Value = "bob";
607 Assert.AreEqual ("bob", dgv.Rows[0].Cells[0].Value, "A3");
611 public void ValueType ()
613 DataGridViewCell c = new BaseCell ();
614 Assert.AreEqual (typeof (bool), c.ValueType, "A1");
616 DataGridView dgv = new DataGridView ();
617 dgv.Columns.Add ("hi", "there");
619 DataGridViewRow row = new DataGridViewRow ();
623 Assert.AreEqual (typeof (bool), dgv.Rows[0].Cells[0].ValueType, "A2");
625 dgv.Rows[0].Cells[0].ValueType = typeof (bool);
626 Assert.AreEqual (typeof (bool), dgv.Rows[0].Cells[0].ValueType, "A3");
630 public void Visible ()
632 DataGridViewCell c = new BaseCell ();
633 Assert.AreEqual (false, c.Visible, "A1");
635 DataGridView dgv = new DataGridView ();
636 dgv.Columns.Add ("hi", "there");
638 DataGridViewRow row = new DataGridViewRow ();
642 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Visible, "A2");
644 dgv.Columns[0].Visible = false;
645 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Visible, "A3");
647 dgv.Columns[0].Visible = true;
648 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Visible, "A4");
650 dgv.Rows[0].Visible = false;
651 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Visible, "A5");
653 dgv.Rows[0].Visible = true;
654 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Visible, "A6");
658 public void MethodBorderWidths ()
660 BaseCell c = new BaseCell ();
662 DataGridViewAdvancedBorderStyle style = new DataGridViewAdvancedBorderStyle ();
663 style.Bottom = DataGridViewAdvancedCellBorderStyle.Inset;
664 style.Left = DataGridViewAdvancedCellBorderStyle.InsetDouble;
665 style.Top = DataGridViewAdvancedCellBorderStyle.None;
666 //style.Right = DataGridViewAdvancedCellBorderStyle.NotSet;
668 Assert.AreEqual (new Rectangle (2, 0, 0, 1), c.PublicBorderWidths (style), "A1");
670 style.Bottom = DataGridViewAdvancedCellBorderStyle.Outset;
671 style.Left = DataGridViewAdvancedCellBorderStyle.OutsetDouble;
672 style.Right = DataGridViewAdvancedCellBorderStyle.OutsetPartial;
673 style.Top = DataGridViewAdvancedCellBorderStyle.Single;
675 Assert.AreEqual (new Rectangle (2, 1, 1, 1), c.PublicBorderWidths (style), "A2");
677 DataGridView dgv = new DataGridView ();
678 dgv.Columns.Add ("hi", "there");
680 DataGridViewRow row = new DataGridViewRow ();
684 dgv.Rows[0].DividerHeight = 3;
685 dgv.Columns[0].DividerWidth = 5;
687 Assert.AreEqual (new Rectangle (2, 1, 6, 4), (dgv.Rows[0].Cells[0] as BaseCell).PublicBorderWidths (style), "A3");
690 /* Font measurement dependent
692 public void MethodGetContentBounds ()
694 DataGridViewCell c = new BaseCell ();
695 Assert.AreEqual (Rectangle.Empty, c.GetContentBounds (c.RowIndex), "A1");
696 c.Value = "hello there";
698 DataGridView dgv = new DataGridView ();
699 dgv.Columns.Add ("hi", "there");
701 DataGridViewRow row = new DataGridViewRow ();
705 Assert.AreEqual (new Rectangle (2, 4, 13, 13), dgv.Rows[0].Cells[0].GetContentBounds (dgv.Rows[0].Cells[0].RowIndex), "A2");
707 dgv.Rows[0].Cells[0].Value = "whoa whoa whoa whoa whoa whoa";
708 Assert.AreEqual (new Rectangle (2, 4, 13, 13), dgv.Rows[0].Cells[0].GetContentBounds (dgv.Rows[0].Cells[0].RowIndex), "A3");
712 public void MethodGetContentBoundsOverload ()
714 Bitmap b = new Bitmap (1, 1);
715 Graphics g = Graphics.FromImage (b);
717 BaseCell c = new BaseCell ();
718 Assert.AreEqual (Rectangle.Empty, c.PublicGetContentBounds (g, c.Style, c.RowIndex), "A1");
720 DataGridView dgv = new DataGridView ();
721 dgv.Columns.Add ("hi", "there");
723 DataGridViewRow row = new DataGridViewRow ();
727 Assert.AreEqual (new Rectangle (2, 4, 13, 13), (dgv.Rows[0].Cells[0] as BaseCell).PublicGetContentBounds (g, dgv.Rows[0].Cells[0].InheritedStyle, dgv.Rows[0].Cells[0].RowIndex), "A2");
734 public void MethodGetErrorIconBounds ()
736 Bitmap b = new Bitmap (1, 1);
737 Graphics g = Graphics.FromImage (b);
739 BaseCell c = new BaseCell ();
740 Assert.AreEqual (Rectangle.Empty, c.PublicGetErrorIconBounds (g, c.Style, c.RowIndex), "A1");
742 DataGridView dgv = new DataGridView ();
743 dgv.Columns.Add ("hi", "there");
745 DataGridViewRow row = new DataGridViewRow ();
749 Assert.AreEqual (Rectangle.Empty, (dgv.Rows[0].Cells[0] as BaseCell).PublicGetErrorIconBounds (g, dgv.Rows[0].Cells[0].InheritedStyle, dgv.Rows[0].Cells[0].RowIndex), "A2");
755 public void MethodGetErrorText ()
757 Bitmap b = new Bitmap (1, 1);
758 Graphics g = Graphics.FromImage (b);
760 BaseCell c = new BaseCell ();
761 Assert.AreEqual (string.Empty, c.PublicGetErrorText (c.RowIndex), "A1");
763 DataGridView dgv = new DataGridView ();
764 dgv.Columns.Add ("hi", "there");
766 DataGridViewRow row = new DataGridViewRow ();
770 Assert.AreEqual (string.Empty, (dgv.Rows[0].Cells[0] as BaseCell).PublicGetErrorText (dgv.Rows[0].Cells[0].RowIndex), "A2");
776 public void MethodKeyEntersEditMode ()
778 string result = string.Empty;
779 string expected = string.Empty;
781 DataGridViewCell c = new BaseCell ();
783 foreach (Keys k in Enum.GetValues (typeof (Keys)))
784 if (c.KeyEntersEditMode (new KeyEventArgs (k)))
785 result += ((int)k).ToString () + ";";
787 Assert.AreEqual (expected, result, "A1");
789 DataGridView dgv = new DataGridView ();
790 dgv.Columns.Add ("hi", "there");
792 DataGridViewRow row = new DataGridViewRow ();
796 result = string.Empty;
798 foreach (Keys k in Enum.GetValues (typeof (Keys)))
799 if (dgv.Rows[0].Cells[0].KeyEntersEditMode (new KeyEventArgs (k)))
800 result += ((int)k).ToString () + ";";
802 Assert.AreEqual (expected, result, "A2");
804 result = string.Empty;
805 dgv.EditMode = DataGridViewEditMode.EditOnEnter;
807 foreach (Keys k in Enum.GetValues (typeof (Keys)))
808 if (dgv.Rows[0].Cells[0].KeyEntersEditMode (new KeyEventArgs (k)))
809 result += ((int)k).ToString () + ";";
811 Assert.AreEqual (expected, result, "A3");
813 result = string.Empty;
814 dgv.EditMode = DataGridViewEditMode.EditOnF2;
816 foreach (Keys k in Enum.GetValues (typeof (Keys)))
817 if (dgv.Rows[0].Cells[0].KeyEntersEditMode (new KeyEventArgs (k)))
818 result += ((int)k).ToString () + ";";
820 Assert.AreEqual (expected, result, "A4");
822 result = string.Empty;
823 dgv.EditMode = DataGridViewEditMode.EditOnKeystroke;
825 foreach (Keys k in Enum.GetValues (typeof (Keys)))
826 if (dgv.Rows[0].Cells[0].KeyEntersEditMode (new KeyEventArgs (k)))
827 result += ((int)k).ToString () + ";";
829 Assert.AreEqual (expected, result, "A5");
831 result = string.Empty;
832 dgv.EditMode = DataGridViewEditMode.EditProgrammatically;
834 foreach (Keys k in Enum.GetValues (typeof (Keys)))
835 if (dgv.Rows[0].Cells[0].KeyEntersEditMode (new KeyEventArgs (k)))
836 result += ((int)k).ToString () + ";";
838 Assert.AreEqual (expected, result, "A6");
842 public void MethodParseFormattedValue ()
844 DataGridViewCell c = new FormattedBaseCell ();
845 c.ValueType = typeof (bool);
847 BooleanConverter bc = new BooleanConverter ();
848 StringConverter sc = new StringConverter ();
850 object o = c.ParseFormattedValue ("true", c.Style, sc, bc);
851 Assert.AreEqual (true, (bool)o, "A1");
855 public void MethodGetInheritedContextMenuStrip ()
857 DataGridViewCell c = new BaseCell ();
858 Assert.AreEqual (null, c.GetInheritedContextMenuStrip (c.RowIndex), "A1");
860 DataGridView dgv = new DataGridView ();
861 dgv.Columns.Add ("hi", "there");
863 DataGridViewRow row = new DataGridViewRow ();
867 Assert.AreEqual (null, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A2");
869 ContextMenuStrip cms1 = new ContextMenuStrip ();
870 cms1.Items.Add ("Moose");
871 dgv.ContextMenuStrip = cms1;
873 Assert.AreSame (cms1, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A3");
875 ContextMenuStrip cms2 = new ContextMenuStrip ();
876 cms2.Items.Add ("Moose");
877 dgv.Columns[0].ContextMenuStrip = cms2;
879 Assert.AreSame (cms2, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A4");
881 dgv.Rows[0].ContextMenuStrip = cms1;
882 Assert.AreSame (cms1, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A5");
884 dgv.Rows[0].Cells[0].ContextMenuStrip = cms2;
885 Assert.AreSame (cms2, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A6");
888 private class FormattedBaseCell : DataGridViewCheckBoxCell
890 public override Type FormattedValueType { get { return typeof (string); } }
893 private class BaseCell : DataGridViewCheckBoxCell
895 public Rectangle PublicGetContentBounds (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex)
896 { return GetContentBounds (graphics, cellStyle, rowIndex); }
897 public Rectangle PublicGetErrorIconBounds (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex)
898 { return GetErrorIconBounds (graphics, cellStyle, rowIndex); }
899 public string PublicGetErrorText (int rowIndex)
900 { return GetErrorText (rowIndex); }
901 public Rectangle PublicBorderWidths (DataGridViewAdvancedBorderStyle advancedBorderStyle)
902 { return BorderWidths (advancedBorderStyle); }