2 // DataGridViewButtonCellTest.cs - Unit tests for
3 // System.Windows.Forms.DataGridViewButtonCellTest
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.
32 using System.Windows.Forms;
34 using NUnit.Framework;
36 using System.Threading;
37 using System.ComponentModel;
39 namespace MonoTests.System.Windows.Forms
42 public class DataGridViewButtonCellTest : TestHelper
47 DataGridViewTextBoxCell tbc = new DataGridViewTextBoxCell ();
48 Assert.IsNull (tbc.Value, "#1");
49 tbc.Value = string.Empty;
50 Assert.AreEqual (string.Empty, tbc.Value, "#2");
52 Assert.AreEqual (5, tbc.Value, "#3");
54 Assert.IsNull (tbc.Value, "#4");
58 public void ColumnIndex ()
60 DataGridViewCell c = new BaseCell ();
61 Assert.AreEqual (-1, c.ColumnIndex, "A1");
63 DataGridView dgv = new DataGridView ();
64 dgv.Columns.Add ("hi", "there");
66 DataGridViewRow row = new DataGridViewRow ();
70 Assert.AreEqual (0, dgv.Rows[0].Cells[0].ColumnIndex, "A2");
73 /* font measurement dependent
75 public void ContentBounds ()
77 DataGridViewCell c = new BaseCell ();
78 Assert.AreEqual (Rectangle.Empty, c.ContentBounds, "A1");
80 DataGridView dgv = new DataGridView ();
81 dgv.Columns.Add ("hi", "there");
83 DataGridViewRow row = new DataGridViewRow ();
87 Assert.AreEqual (new Rectangle (0, 0, 99, 21), dgv.Rows[0].Cells[0].ContentBounds, "A2");
92 public void ContextMenuStrip ()
94 DataGridViewCell c = new BaseCell ();
95 Assert.AreEqual (null, c.ContextMenuStrip, "A1");
97 DataGridView dgv = new DataGridView ();
98 dgv.Columns.Add ("hi", "there");
100 DataGridViewRow row = new DataGridViewRow ();
104 ContextMenuStrip cms1 = new ContextMenuStrip ();
105 cms1.Items.Add ("hey");
107 ContextMenuStrip cms2 = new ContextMenuStrip ();
108 cms2.Items.Add ("yo");
110 dgv.Rows[0].ContextMenuStrip = cms1;
111 Assert.AreEqual (null, dgv.Rows[0].Cells[0].ContextMenuStrip, "A2");
113 dgv.Rows[0].Cells[0].ContextMenuStrip = cms2;
114 Assert.AreSame (cms2, dgv.Rows[0].Cells[0].ContextMenuStrip, "A3");
118 public void DataGridView ()
120 DataGridViewCell c = new BaseCell ();
121 Assert.AreEqual (null, c.DataGridView, "A1");
123 DataGridView dgv = new DataGridView ();
124 dgv.Columns.Add ("hi", "there");
126 DataGridViewRow row = new DataGridViewRow ();
130 Assert.AreSame (dgv, dgv.Rows[0].Cells[0].DataGridView, "A2");
134 public void DefaultNewRowValue ()
136 DataGridViewCell c = new BaseCell ();
137 Assert.AreEqual (null, c.DefaultNewRowValue, "A1");
139 DataGridView dgv = new DataGridView ();
140 dgv.Columns.Add ("hi", "there");
142 DataGridViewRow row = new DataGridViewRow ();
146 Assert.AreEqual (null, dgv.Rows[0].Cells[0].DefaultNewRowValue, "A2");
150 public void Displayed ()
152 DataGridViewCell c = new BaseCell ();
153 Assert.AreEqual (false, c.Displayed, "A1");
155 DataGridView dgv = new DataGridView ();
156 dgv.Columns.Add ("hi", "there");
158 DataGridViewRow row = new DataGridViewRow ();
162 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Displayed, "A2");
166 public void EditedFormattedValue ()
168 DataGridViewCell c = new BaseCell ();
169 Assert.AreEqual (null, c.EditedFormattedValue, "A1");
173 public void FormattedValueType ()
175 DataGridViewCell c = new BaseCell ();
176 Assert.AreEqual (typeof (string), c.FormattedValueType, "A1");
180 public void Frozen ()
182 DataGridViewCell c = new BaseCell ();
183 Assert.AreEqual (false, c.Frozen, "A1");
185 DataGridView dgv = new DataGridView ();
186 dgv.Columns.Add ("hi", "there");
188 DataGridViewRow row = new DataGridViewRow ();
192 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Frozen, "A2");
194 dgv.Columns[0].Frozen = true;
195 dgv.Rows[0].Frozen = true;
196 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Frozen, "A3");
200 public void HasStyle ()
202 DataGridViewCell c = new BaseCell ();
203 Assert.AreEqual (false, c.HasStyle, "A1");
205 DataGridView dgv = new DataGridView ();
206 dgv.Columns.Add ("hi", "there");
208 DataGridViewRow row = new DataGridViewRow ();
212 Assert.AreEqual (false, dgv.Rows[0].Cells[0].HasStyle, "A2");
214 dgv.Rows[0].Cells[0].Style.BackColor = Color.Orange;
215 Assert.AreEqual (true, dgv.Rows[0].Cells[0].HasStyle, "A3");
219 public void InheritedState ()
221 DataGridViewCell c = new BaseCell ();
222 Assert.AreEqual (DataGridViewElementStates.ResizableSet, c.InheritedState, "A1");
224 DataGridView dgv = new DataGridView ();
225 dgv.Columns.Add ("hi", "there");
227 DataGridViewRow row = new DataGridViewRow ();
231 Assert.AreEqual (DataGridViewElementStates.ResizableSet | DataGridViewElementStates.Resizable | DataGridViewElementStates.Visible, dgv.Rows[0].Cells[0].InheritedState, "A2");
233 dgv.Rows[0].Selected = true;
234 Assert.AreEqual (DataGridViewElementStates.Selected | DataGridViewElementStates.ResizableSet | DataGridViewElementStates.Resizable | DataGridViewElementStates.Visible, dgv.Rows[0].Cells[0].InheritedState, "A3");
236 dgv.Rows[0].Selected = false;
237 dgv.Columns[0].Selected = true;
238 Assert.AreEqual (DataGridViewElementStates.ResizableSet | DataGridViewElementStates.Resizable | DataGridViewElementStates.Visible, dgv.Rows[0].Cells[0].InheritedState, "A4");
242 public void InheritedStyle ()
244 DataGridViewCell c = new BaseCell ();
245 DataGridView dgv = new DataGridView ();
246 dgv.Columns.Add ("hi", "there");
248 DataGridViewRow row = new DataGridViewRow ();
252 Assert.AreEqual (SystemColors.Window, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A1");
254 dgv.DefaultCellStyle.BackColor = Color.Firebrick;
255 Assert.AreEqual (Color.Firebrick, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A2");
257 dgv.Columns[0].DefaultCellStyle.BackColor = Color.FloralWhite;
258 Assert.AreEqual (Color.FloralWhite, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A3");
260 dgv.RowsDefaultCellStyle.BackColor = Color.DeepPink;
261 Assert.AreEqual (Color.DeepPink, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A4");
263 dgv.Rows[0].DefaultCellStyle.BackColor = Color.DeepSkyBlue;
264 Assert.AreEqual (Color.DeepSkyBlue, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A5");
266 dgv.Rows[0].Cells[0].Style.BackColor = Color.DodgerBlue;
267 Assert.AreEqual (Color.DodgerBlue, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A6");
271 public void IsInEditMode ()
273 DataGridViewCell c = new BaseCell ();
274 Assert.AreEqual (false, c.IsInEditMode, "A1");
276 DataGridView dgv = new DataGridView ();
277 dgv.Columns.Add ("hi", "there");
279 DataGridViewRow row = new DataGridViewRow ();
283 Assert.AreEqual (false, dgv.Rows[0].Cells[0].IsInEditMode, "A2");
287 public void OwningColumn ()
289 DataGridViewCell c = new BaseCell ();
290 Assert.AreEqual (null, c.OwningColumn, "A1");
292 DataGridView dgv = new DataGridView ();
293 dgv.Columns.Add ("hi", "there");
295 DataGridViewRow row = new DataGridViewRow ();
299 Assert.AreSame (dgv.Columns[0], dgv.Rows[0].Cells[0].OwningColumn, "A2");
303 public void OwningRow ()
305 DataGridViewCell c = new BaseCell ();
306 Assert.AreEqual (null, c.OwningRow, "A1");
308 DataGridView dgv = new DataGridView ();
309 dgv.Columns.Add ("hi", "there");
311 DataGridViewRow row = new DataGridViewRow ();
315 Assert.AreSame (dgv.Rows[0], dgv.Rows[0].Cells[0].OwningRow, "A2");
318 /* Font measurement dependent *
320 public void PreferredSize ()
322 DataGridViewCell c = new BaseCell ();
323 Assert.AreEqual (new Size (-1, -1), c.PreferredSize, "A1");
325 DataGridView dgv = new DataGridView ();
326 dgv.Columns.Add ("hi", "there");
328 DataGridViewRow row = new DataGridViewRow ();
332 Assert.AreEqual (new Size (21, 21), dgv.Rows[0].Cells[0].PreferredSize, "A2");
334 dgv.Rows[0].Cells[0].Value = "bob";
335 Assert.AreEqual (new Size (35, 21), dgv.Rows[0].Cells[0].PreferredSize, "A3");
337 dgv.Rows[0].Cells[0].Value = "roasted quail";
338 Assert.AreEqual (new Size (77, 21), dgv.Rows[0].Cells[0].PreferredSize, "A3");
343 public void ReadOnly ()
345 DataGridViewCell c = new BaseCell ();
346 Assert.AreEqual (false, c.ReadOnly, "A1");
348 DataGridView dgv = new DataGridView ();
349 dgv.Columns.Add ("hi", "there");
351 DataGridViewRow row = new DataGridViewRow ();
355 Assert.AreEqual (false, dgv.Rows[0].Cells[0].ReadOnly, "A2");
357 dgv.Rows[0].ReadOnly = true;
358 Assert.AreEqual (true, dgv.Rows[0].Cells[0].ReadOnly, "A3");
360 dgv.Rows[0].Cells[0].ReadOnly = false;
361 Assert.AreEqual (false, dgv.Rows[0].Cells[0].ReadOnly, "A4");
365 public void Resizable ()
367 DataGridViewCell c = new BaseCell ();
368 Assert.AreEqual (false, c.Resizable, "A1");
370 DataGridView dgv = new DataGridView ();
371 dgv.Columns.Add ("hi", "there");
373 DataGridViewRow row = new DataGridViewRow ();
377 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Resizable, "A2");
379 dgv.Rows[0].Resizable = DataGridViewTriState.False;
380 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Resizable, "A3");
382 dgv.Columns[0].Resizable = DataGridViewTriState.False;
383 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Resizable, "A4");
385 dgv.Columns[0].Resizable = DataGridViewTriState.True;
386 dgv.Rows[0].Resizable = DataGridViewTriState.True;
387 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Resizable, "A5");
389 dgv.AllowUserToResizeColumns = false;
390 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Resizable, "A6");
392 dgv.AllowUserToResizeRows = false;
393 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Resizable, "A7");
395 dgv.Columns[0].Resizable = DataGridViewTriState.NotSet;
396 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Resizable, "A8");
398 dgv.Rows[0].Resizable = DataGridViewTriState.NotSet;
399 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Resizable, "A9");
403 public void RowIndex ()
405 DataGridViewCell c = new BaseCell ();
406 Assert.AreEqual (-1, c.RowIndex, "A1");
408 DataGridView dgv = new DataGridView ();
409 dgv.Columns.Add ("hi", "there");
411 DataGridViewRow row = new DataGridViewRow ();
415 Assert.AreEqual (0, dgv.Rows[0].Cells[0].RowIndex, "A2");
419 public void Selected ()
421 DataGridViewCell c = new BaseCell ();
422 Assert.AreEqual (false, c.Selected, "A1");
424 DataGridView dgv = new DataGridView ();
425 dgv.Columns.Add ("hi", "there");
427 DataGridViewRow row = new DataGridViewRow ();
431 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Selected, "A2");
433 dgv.Columns[0].Selected = true;
434 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Selected, "A3");
436 dgv.Rows[0].Selected = true;
437 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Selected, "A4");
439 dgv.Rows[0].Cells[0].Selected = false;
440 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Selected, "A5");
442 dgv.Rows[0].Selected = false;
443 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Selected, "A6");
445 dgv.Rows[0].Cells[0].Selected = true;
446 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Selected, "A7");
449 /* The height of a cell (row) is based on Font
453 DataGridViewCell c = new BaseCell ();
454 Assert.AreEqual (new Size (-1, -1), c.Size, "A1");
456 DataGridView dgv = new DataGridView ();
457 dgv.Columns.Add ("hi", "there");
459 DataGridViewRow row = new DataGridViewRow ();
463 Assert.AreEqual (new Size (100, 22), dgv.Rows[0].Cells[0].Size, "A2");
465 // Does not resize to content
466 dgv.Rows[0].Cells[0].Value = "bob";
467 Assert.AreEqual (new Size (100, 22), dgv.Rows[0].Cells[0].Size, "A3");
474 DataGridViewCell c = new BaseCell ();
475 Assert.AreEqual (DataGridViewContentAlignment.NotSet, c.Style.Alignment, "A1");
476 Assert.AreEqual (Color.Empty, c.Style.BackColor, "A2");
477 Assert.AreEqual (DBNull.Value, c.Style.DataSourceNullValue, "A3");
478 Assert.AreEqual (null, c.Style.Font, "A4");
479 Assert.AreEqual (Color.Empty, c.Style.ForeColor, "A5");
480 Assert.AreEqual (string.Empty, c.Style.Format, "A6");
481 Assert.AreEqual (Thread.CurrentThread.CurrentCulture, c.Style.FormatProvider, "A7");
482 Assert.AreEqual (true, c.Style.IsDataSourceNullValueDefault, "A8");
483 Assert.AreEqual (true, c.Style.IsFormatProviderDefault, "A9");
484 Assert.AreEqual (true, c.Style.IsNullValueDefault, "A10");
485 Assert.AreEqual (string.Empty, c.Style.NullValue, "A11");
486 Assert.AreEqual (Padding.Empty, c.Style.Padding, "A12");
487 Assert.AreEqual (Color.Empty, c.Style.SelectionBackColor, "A13");
488 Assert.AreEqual (Color.Empty, c.Style.SelectionForeColor, "A14");
489 Assert.AreEqual (null, c.Style.Tag, "A15");
490 Assert.AreEqual (DataGridViewTriState.NotSet, c.Style.WrapMode, "A16");
492 DataGridView dgv = new DataGridView ();
493 dgv.Columns.Add ("hi", "there");
495 DataGridViewRow row = new DataGridViewRow ();
499 // Style does not change based on parent
500 // (InheritedStyle does)
501 Assert.AreEqual (DataGridViewContentAlignment.NotSet, c.Style.Alignment, "A17");
502 Assert.AreEqual (Color.Empty, c.Style.BackColor, "A18");
503 Assert.AreEqual (DBNull.Value, c.Style.DataSourceNullValue, "A19");
504 Assert.AreEqual (null, c.Style.Font, "A20");
505 Assert.AreEqual (Color.Empty, c.Style.ForeColor, "A21");
506 Assert.AreEqual (string.Empty, c.Style.Format, "A22");
507 Assert.AreEqual (Thread.CurrentThread.CurrentCulture, c.Style.FormatProvider, "A23");
508 Assert.AreEqual (true, c.Style.IsDataSourceNullValueDefault, "A24");
509 Assert.AreEqual (true, c.Style.IsFormatProviderDefault, "A25");
510 Assert.AreEqual (true, c.Style.IsNullValueDefault, "A26");
511 Assert.AreEqual (string.Empty, c.Style.NullValue, "A27");
512 Assert.AreEqual (Padding.Empty, c.Style.Padding, "A28");
513 Assert.AreEqual (Color.Empty, c.Style.SelectionBackColor, "A29");
514 Assert.AreEqual (Color.Empty, c.Style.SelectionForeColor, "A30");
515 Assert.AreEqual (null, c.Style.Tag, "A31");
516 Assert.AreEqual (DataGridViewTriState.NotSet, c.Style.WrapMode, "A32");
522 DataGridViewCell c = new BaseCell ();
523 Assert.AreEqual (null, c.Tag, "A1");
525 DataGridView dgv = new DataGridView ();
526 dgv.Columns.Add ("hi", "there");
528 DataGridViewRow row = new DataGridViewRow ();
532 Assert.AreEqual (null, dgv.Rows[0].Cells[0].Tag, "A2");
534 dgv.Rows[0].Cells[0].Tag = "bob";
535 Assert.AreEqual ("bob", dgv.Rows[0].Cells[0].Tag, "A3");
539 public void ToolTipText ()
541 DataGridViewCell c = new BaseCell ();
542 Assert.AreEqual (string.Empty, c.ToolTipText, "A1");
544 DataGridView dgv = new DataGridView ();
545 dgv.Columns.Add ("hi", "there");
547 DataGridViewRow row = new DataGridViewRow ();
551 Assert.AreEqual (string.Empty, dgv.Rows[0].Cells[0].ToolTipText, "A2");
553 dgv.Rows[0].Cells[0].ToolTipText = "bob";
554 Assert.AreEqual ("bob", dgv.Rows[0].Cells[0].ToolTipText, "A3");
558 public void Value2 ()
560 DataGridViewCell c = new BaseCell ();
561 Assert.AreEqual (null, c.Value, "A1");
563 DataGridView dgv = new DataGridView ();
564 dgv.Columns.Add ("hi", "there");
566 DataGridViewRow row = new DataGridViewRow ();
570 Assert.AreEqual (null, dgv.Rows[0].Cells[0].Value, "A2");
572 dgv.Rows[0].Cells[0].Value = "bob";
573 Assert.AreEqual ("bob", dgv.Rows[0].Cells[0].Value, "A3");
577 public void ValueType ()
579 DataGridViewCell c = new BaseCell ();
580 Assert.AreEqual (typeof (object), c.ValueType, "A1");
582 DataGridView dgv = new DataGridView ();
583 dgv.Columns.Add ("hi", "there");
585 DataGridViewRow row = new DataGridViewRow ();
589 Assert.AreEqual (typeof (object), dgv.Rows[0].Cells[0].ValueType, "A2");
591 dgv.Rows[0].Cells[0].ValueType = typeof (bool);
592 Assert.AreEqual (typeof (bool), dgv.Rows[0].Cells[0].ValueType, "A3");
596 public void Visible ()
598 DataGridViewCell c = new BaseCell ();
599 Assert.AreEqual (false, c.Visible, "A1");
601 DataGridView dgv = new DataGridView ();
602 dgv.Columns.Add ("hi", "there");
604 DataGridViewRow row = new DataGridViewRow ();
608 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Visible, "A2");
610 dgv.Columns[0].Visible = false;
611 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Visible, "A3");
613 dgv.Columns[0].Visible = true;
614 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Visible, "A4");
616 dgv.Rows[0].Visible = false;
617 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Visible, "A5");
619 dgv.Rows[0].Visible = true;
620 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Visible, "A6");
624 public void MethodBorderWidths ()
626 BaseCell c = new BaseCell ();
628 DataGridViewAdvancedBorderStyle style = new DataGridViewAdvancedBorderStyle ();
629 style.Bottom = DataGridViewAdvancedCellBorderStyle.Inset;
630 style.Left = DataGridViewAdvancedCellBorderStyle.InsetDouble;
631 style.Top = DataGridViewAdvancedCellBorderStyle.None;
632 //style.Right = DataGridViewAdvancedCellBorderStyle.NotSet;
634 Assert.AreEqual (new Rectangle (2, 0, 0, 1), c.PublicBorderWidths (style), "A1");
636 style.Bottom = DataGridViewAdvancedCellBorderStyle.Outset;
637 style.Left = DataGridViewAdvancedCellBorderStyle.OutsetDouble;
638 style.Right = DataGridViewAdvancedCellBorderStyle.OutsetPartial;
639 style.Top = DataGridViewAdvancedCellBorderStyle.Single;
641 Assert.AreEqual (new Rectangle (2, 1, 1, 1), c.PublicBorderWidths (style), "A2");
643 DataGridView dgv = new DataGridView ();
644 dgv.Columns.Add ("hi", "there");
646 DataGridViewRow row = new DataGridViewRow ();
650 dgv.Rows[0].DividerHeight = 3;
651 dgv.Columns[0].DividerWidth = 5;
653 Assert.AreEqual (new Rectangle (2, 1, 6, 4), (dgv.Rows[0].Cells[0] as BaseCell).PublicBorderWidths (style), "A3");
656 /* Font measurement dependent
658 public void MethodGetContentBounds ()
660 DataGridViewCell c = new BaseCell ();
661 Assert.AreEqual (Rectangle.Empty, c.GetContentBounds (c.RowIndex), "A1");
662 c.Value = "hello there";
664 DataGridView dgv = new DataGridView ();
665 dgv.Columns.Add ("hi", "there");
667 DataGridViewRow row = new DataGridViewRow ();
671 Assert.AreEqual (new Rectangle (0, 0, 99, 21), dgv.Rows[0].Cells[0].GetContentBounds (dgv.Rows[0].Cells[0].RowIndex), "A2");
673 dgv.Rows[0].Cells[0].Value = "whoa whoa whoa whoa whoa whoa";
674 Assert.AreEqual (new Rectangle (0, 0, 99, 21), dgv.Rows[0].Cells[0].GetContentBounds (dgv.Rows[0].Cells[0].RowIndex), "A3");
678 public void MethodGetContentBoundsOverload ()
680 Bitmap b = new Bitmap (1, 1);
681 Graphics g = Graphics.FromImage (b);
683 BaseCell c = new BaseCell ();
684 Assert.AreEqual (Rectangle.Empty, c.PublicGetContentBounds (g, c.Style, c.RowIndex), "A1");
686 DataGridView dgv = new DataGridView ();
687 dgv.Columns.Add ("hi", "there");
689 DataGridViewRow row = new DataGridViewRow ();
693 Assert.AreEqual (new Rectangle (0, 0, 99, 21), (dgv.Rows[0].Cells[0] as BaseCell).PublicGetContentBounds (g, dgv.Rows[0].Cells[0].InheritedStyle, dgv.Rows[0].Cells[0].RowIndex), "A2");
700 public void MethodGetErrorIconBounds ()
702 Bitmap b = new Bitmap (1, 1);
703 Graphics g = Graphics.FromImage (b);
705 BaseCell c = new BaseCell ();
706 Assert.AreEqual (Rectangle.Empty, c.PublicGetErrorIconBounds (g, c.Style, c.RowIndex), "A1");
708 DataGridView dgv = new DataGridView ();
709 dgv.Columns.Add ("hi", "there");
711 DataGridViewRow row = new DataGridViewRow ();
715 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");
721 public void MethodGetErrorText ()
723 Bitmap b = new Bitmap (1, 1);
724 Graphics g = Graphics.FromImage (b);
726 BaseCell c = new BaseCell ();
727 Assert.AreEqual (string.Empty, c.PublicGetErrorText (c.RowIndex), "A1");
729 DataGridView dgv = new DataGridView ();
730 dgv.Columns.Add ("hi", "there");
732 DataGridViewRow row = new DataGridViewRow ();
736 Assert.AreEqual (string.Empty, (dgv.Rows[0].Cells[0] as BaseCell).PublicGetErrorText (dgv.Rows[0].Cells[0].RowIndex), "A2");
742 public void MethodKeyEntersEditMode ()
744 string result = string.Empty;
745 string expected = string.Empty;
747 DataGridViewCell c = new BaseCell ();
749 foreach (Keys k in Enum.GetValues (typeof (Keys)))
750 if (c.KeyEntersEditMode (new KeyEventArgs (k)))
751 result += ((int)k).ToString () + ";";
753 Assert.AreEqual (expected, result, "A1");
755 DataGridView dgv = new DataGridView ();
756 dgv.Columns.Add ("hi", "there");
758 DataGridViewRow row = new DataGridViewRow ();
762 result = string.Empty;
764 foreach (Keys k in Enum.GetValues (typeof (Keys)))
765 if (dgv.Rows[0].Cells[0].KeyEntersEditMode (new KeyEventArgs (k)))
766 result += ((int)k).ToString () + ";";
768 Assert.AreEqual (expected, result, "A2");
770 result = string.Empty;
771 dgv.EditMode = DataGridViewEditMode.EditOnEnter;
773 foreach (Keys k in Enum.GetValues (typeof (Keys)))
774 if (dgv.Rows[0].Cells[0].KeyEntersEditMode (new KeyEventArgs (k)))
775 result += ((int)k).ToString () + ";";
777 Assert.AreEqual (expected, result, "A3");
779 result = string.Empty;
780 dgv.EditMode = DataGridViewEditMode.EditOnF2;
782 foreach (Keys k in Enum.GetValues (typeof (Keys)))
783 if (dgv.Rows[0].Cells[0].KeyEntersEditMode (new KeyEventArgs (k)))
784 result += ((int)k).ToString () + ";";
786 Assert.AreEqual (expected, result, "A4");
788 result = string.Empty;
789 dgv.EditMode = DataGridViewEditMode.EditOnKeystroke;
791 foreach (Keys k in Enum.GetValues (typeof (Keys)))
792 if (dgv.Rows[0].Cells[0].KeyEntersEditMode (new KeyEventArgs (k)))
793 result += ((int)k).ToString () + ";";
795 Assert.AreEqual (expected, result, "A5");
797 result = string.Empty;
798 dgv.EditMode = DataGridViewEditMode.EditProgrammatically;
800 foreach (Keys k in Enum.GetValues (typeof (Keys)))
801 if (dgv.Rows[0].Cells[0].KeyEntersEditMode (new KeyEventArgs (k)))
802 result += ((int)k).ToString () + ";";
804 Assert.AreEqual (expected, result, "A6");
808 public void MethodParseFormattedValue ()
810 DataGridViewCell c = new FormattedBaseCell ();
811 c.ValueType = typeof (bool);
813 BooleanConverter bc = new BooleanConverter ();
814 StringConverter sc = new StringConverter ();
816 object o = c.ParseFormattedValue ("true", c.Style, sc, bc);
817 Assert.AreEqual (true, (bool)o, "A1");
821 public void MethodGetInheritedContextMenuStrip ()
823 DataGridViewCell c = new BaseCell ();
824 Assert.AreEqual (null, c.GetInheritedContextMenuStrip (c.RowIndex), "A1");
826 DataGridView dgv = new DataGridView ();
827 dgv.Columns.Add ("hi", "there");
829 DataGridViewRow row = new DataGridViewRow ();
833 Assert.AreEqual (null, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A2");
835 ContextMenuStrip cms1 = new ContextMenuStrip ();
836 cms1.Items.Add ("Moose");
837 dgv.ContextMenuStrip = cms1;
839 Assert.AreSame (cms1, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A3");
841 ContextMenuStrip cms2 = new ContextMenuStrip ();
842 cms2.Items.Add ("Moose");
843 dgv.Columns[0].ContextMenuStrip = cms2;
845 Assert.AreSame (cms2, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A4");
847 dgv.Rows[0].ContextMenuStrip = cms1;
848 Assert.AreSame (cms1, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A5");
850 dgv.Rows[0].Cells[0].ContextMenuStrip = cms2;
851 Assert.AreSame (cms2, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A6");
854 private class FormattedBaseCell : DataGridViewButtonCell
856 public override Type FormattedValueType { get { return typeof (string); } }
859 private class BaseCell : DataGridViewButtonCell
861 public Rectangle PublicGetContentBounds (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex)
862 { return GetContentBounds (graphics, cellStyle, rowIndex); }
863 public Rectangle PublicGetErrorIconBounds (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex)
864 { return GetErrorIconBounds (graphics, cellStyle, rowIndex); }
865 public string PublicGetErrorText (int rowIndex)
866 { return GetErrorText (rowIndex); }
867 public Rectangle PublicBorderWidths (DataGridViewAdvancedBorderStyle advancedBorderStyle)
868 { return BorderWidths (advancedBorderStyle); }