2 // DataGridViewImageCellTest.cs - Unit tests for
3 // System.Windows.Forms.DataGridViewImageCellTest
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 DataGridViewImageCellTest : TestHelper
48 DataGridViewImageCell tbc = new DataGridViewImageCell ();
49 Assert.IsNull (tbc.Value, "#1");
50 tbc.Value = string.Empty;
51 Assert.AreEqual (string.Empty, tbc.Value, "#2");
53 Assert.AreEqual (5, tbc.Value, "#3");
55 Assert.IsNull (tbc.Value, "#4");
59 public void ColumnIndex ()
61 DataGridViewCell c = new BaseCell ();
62 Assert.AreEqual (-1, c.ColumnIndex, "A1");
64 DataGridView dgv = new DataGridView ();
65 dgv.Columns.Add ("hi", "there");
67 DataGridViewRow row = new DataGridViewRow ();
71 Assert.AreEqual (0, dgv.Rows[0].Cells[0].ColumnIndex, "A2");
74 /* font measurement dependent
76 public void ContentBounds ()
78 DataGridViewCell c = new BaseCell ();
79 Assert.AreEqual (Rectangle.Empty, c.ContentBounds, "A1");
81 DataGridView dgv = new DataGridView ();
82 dgv.Columns.Add ("hi", "there");
84 DataGridViewRow row = new DataGridViewRow ();
88 Assert.AreEqual (new Rectangle (0, 2, 14, 16), dgv.Rows[0].Cells[0].ContentBounds, "A2");
93 public void ContextMenuStrip ()
95 DataGridViewCell c = new BaseCell ();
96 Assert.AreEqual (null, c.ContextMenuStrip, "A1");
98 DataGridView dgv = new DataGridView ();
99 dgv.Columns.Add ("hi", "there");
101 DataGridViewRow row = new DataGridViewRow ();
105 ContextMenuStrip cms1 = new ContextMenuStrip ();
106 cms1.Items.Add ("hey");
108 ContextMenuStrip cms2 = new ContextMenuStrip ();
109 cms2.Items.Add ("yo");
111 dgv.Rows[0].ContextMenuStrip = cms1;
112 Assert.AreEqual (null, dgv.Rows[0].Cells[0].ContextMenuStrip, "A2");
114 dgv.Rows[0].Cells[0].ContextMenuStrip = cms2;
115 Assert.AreSame (cms2, dgv.Rows[0].Cells[0].ContextMenuStrip, "A3");
119 public void DataGridView ()
121 DataGridViewCell c = new BaseCell ();
122 Assert.AreEqual (null, c.DataGridView, "A1");
124 DataGridView dgv = new DataGridView ();
125 dgv.Columns.Add ("hi", "there");
127 DataGridViewRow row = new DataGridViewRow ();
131 Assert.AreSame (dgv, dgv.Rows[0].Cells[0].DataGridView, "A2");
135 public void DefaultNewRowValue ()
137 DataGridViewCell c = new BaseCell ();
138 Assert.AreEqual ("System.Drawing.Bitmap", c.DefaultNewRowValue.GetType ().ToString (), "A1");
140 DataGridView dgv = new DataGridView ();
141 dgv.Columns.Add ("hi", "there");
143 DataGridViewRow row = new DataGridViewRow ();
147 Assert.AreEqual ("System.Drawing.Bitmap", dgv.Rows[0].Cells[0].DefaultNewRowValue.GetType ().ToString (), "A2");
151 public void Displayed ()
153 DataGridViewCell c = new BaseCell ();
154 Assert.AreEqual (false, c.Displayed, "A1");
156 DataGridView dgv = new DataGridView ();
157 dgv.Columns.Add ("hi", "there");
159 DataGridViewRow row = new DataGridViewRow ();
163 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Displayed, "A2");
167 public void EditedFormattedValue ()
169 DataGridViewCell c = new BaseCell ();
170 Assert.AreEqual (null, c.EditedFormattedValue, "A1");
174 public void FormattedValueType ()
176 DataGridViewCell c = new BaseCell ();
177 Assert.AreEqual (typeof (Image), c.FormattedValueType, "A1");
181 public void Frozen ()
183 DataGridViewCell c = new BaseCell ();
184 Assert.AreEqual (false, c.Frozen, "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].Frozen, "A2");
195 dgv.Columns[0].Frozen = true;
196 dgv.Rows[0].Frozen = true;
197 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Frozen, "A3");
201 public void HasStyle ()
203 DataGridViewCell c = new BaseCell ();
204 Assert.AreEqual (false, c.HasStyle, "A1");
206 DataGridView dgv = new DataGridView ();
207 dgv.Columns.Add ("hi", "there");
209 DataGridViewRow row = new DataGridViewRow ();
213 Assert.AreEqual (false, dgv.Rows[0].Cells[0].HasStyle, "A2");
215 dgv.Rows[0].Cells[0].Style.BackColor = Color.Orange;
216 Assert.AreEqual (true, dgv.Rows[0].Cells[0].HasStyle, "A3");
220 public void InheritedState ()
222 DataGridViewCell c = new BaseCell ();
223 Assert.AreEqual (DataGridViewElementStates.ResizableSet, c.InheritedState, "A1");
225 DataGridView dgv = new DataGridView ();
226 dgv.Columns.Add ("hi", "there");
228 DataGridViewRow row = new DataGridViewRow ();
232 Assert.AreEqual (DataGridViewElementStates.ResizableSet | DataGridViewElementStates.Resizable | DataGridViewElementStates.Visible, dgv.Rows[0].Cells[0].InheritedState, "A2");
234 dgv.Rows[0].Selected = true;
235 Assert.AreEqual (DataGridViewElementStates.Selected | DataGridViewElementStates.ResizableSet | DataGridViewElementStates.Resizable | DataGridViewElementStates.Visible, dgv.Rows[0].Cells[0].InheritedState, "A3");
237 dgv.Rows[0].Selected = false;
238 dgv.Columns[0].Selected = true;
239 Assert.AreEqual (DataGridViewElementStates.ResizableSet | DataGridViewElementStates.Resizable | DataGridViewElementStates.Visible, dgv.Rows[0].Cells[0].InheritedState, "A4");
243 public void InheritedStyle ()
245 DataGridViewCell c = new BaseCell ();
246 DataGridView dgv = new DataGridView ();
247 dgv.Columns.Add ("hi", "there");
249 DataGridViewRow row = new DataGridViewRow ();
253 Assert.AreEqual (SystemColors.Window, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A1");
255 dgv.DefaultCellStyle.BackColor = Color.Firebrick;
256 Assert.AreEqual (Color.Firebrick, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A2");
258 dgv.Columns[0].DefaultCellStyle.BackColor = Color.FloralWhite;
259 Assert.AreEqual (Color.FloralWhite, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A3");
261 dgv.RowsDefaultCellStyle.BackColor = Color.DeepPink;
262 Assert.AreEqual (Color.DeepPink, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A4");
264 dgv.Rows[0].DefaultCellStyle.BackColor = Color.DeepSkyBlue;
265 Assert.AreEqual (Color.DeepSkyBlue, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A5");
267 dgv.Rows[0].Cells[0].Style.BackColor = Color.DodgerBlue;
268 Assert.AreEqual (Color.DodgerBlue, dgv.Rows[0].Cells[0].InheritedStyle.BackColor, "A6");
272 public void IsInEditMode ()
274 DataGridViewCell c = new BaseCell ();
275 Assert.AreEqual (false, c.IsInEditMode, "A1");
277 DataGridView dgv = new DataGridView ();
278 dgv.Columns.Add ("hi", "there");
280 DataGridViewRow row = new DataGridViewRow ();
284 Assert.AreEqual (false, dgv.Rows[0].Cells[0].IsInEditMode, "A2");
288 public void OwningColumn ()
290 DataGridViewCell c = new BaseCell ();
291 Assert.AreEqual (null, c.OwningColumn, "A1");
293 DataGridView dgv = new DataGridView ();
294 dgv.Columns.Add ("hi", "there");
296 DataGridViewRow row = new DataGridViewRow ();
300 Assert.AreSame (dgv.Columns[0], dgv.Rows[0].Cells[0].OwningColumn, "A2");
304 public void OwningRow ()
306 DataGridViewCell c = new BaseCell ();
307 Assert.AreEqual (null, c.OwningRow, "A1");
309 DataGridView dgv = new DataGridView ();
310 dgv.Columns.Add ("hi", "there");
312 DataGridViewRow row = new DataGridViewRow ();
316 Assert.AreSame (dgv.Rows[0], dgv.Rows[0].Cells[0].OwningRow, "A2");
319 /* Font measurement dependent *
321 public void PreferredSize ()
323 DataGridViewCell c = new BaseCell ();
324 Assert.AreEqual (new Size (-1, -1), c.PreferredSize, "A1");
326 DataGridView dgv = new DataGridView ();
327 dgv.Columns.Add ("hi", "there");
329 DataGridViewRow row = new DataGridViewRow ();
333 Assert.AreEqual (new Size (21, 20), dgv.Rows[0].Cells[0].PreferredSize, "A2");
335 dgv.Rows[0].Cells[0].Value = new Bitmap (20, 20);
336 Assert.AreEqual (new Size (21, 21), dgv.Rows[0].Cells[0].PreferredSize, "A3");
338 dgv.Rows[0].Cells[0].Value = new Bitmap (32, 32);
339 Assert.AreEqual (new Size (33, 33), dgv.Rows[0].Cells[0].PreferredSize, "A4");
344 public void ReadOnly ()
346 DataGridViewCell c = new BaseCell ();
347 Assert.AreEqual (false, c.ReadOnly, "A1");
349 DataGridView dgv = new DataGridView ();
350 dgv.Columns.Add ("hi", "there");
352 DataGridViewRow row = new DataGridViewRow ();
356 Assert.AreEqual (false, dgv.Rows[0].Cells[0].ReadOnly, "A2");
358 dgv.Rows[0].ReadOnly = true;
359 Assert.AreEqual (true, dgv.Rows[0].Cells[0].ReadOnly, "A3");
361 dgv.Rows[0].Cells[0].ReadOnly = false;
362 Assert.AreEqual (false, dgv.Rows[0].Cells[0].ReadOnly, "A4");
366 public void Resizable ()
368 DataGridViewCell c = new BaseCell ();
369 Assert.AreEqual (false, c.Resizable, "A1");
371 DataGridView dgv = new DataGridView ();
372 dgv.Columns.Add ("hi", "there");
374 DataGridViewRow row = new DataGridViewRow ();
378 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Resizable, "A2");
380 dgv.Rows[0].Resizable = DataGridViewTriState.False;
381 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Resizable, "A3");
383 dgv.Columns[0].Resizable = DataGridViewTriState.False;
384 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Resizable, "A4");
386 dgv.Columns[0].Resizable = DataGridViewTriState.True;
387 dgv.Rows[0].Resizable = DataGridViewTriState.True;
388 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Resizable, "A5");
390 dgv.AllowUserToResizeColumns = false;
391 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Resizable, "A6");
393 dgv.AllowUserToResizeRows = false;
394 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Resizable, "A7");
396 dgv.Columns[0].Resizable = DataGridViewTriState.NotSet;
397 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Resizable, "A8");
399 dgv.Rows[0].Resizable = DataGridViewTriState.NotSet;
400 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Resizable, "A9");
404 public void RowIndex ()
406 DataGridViewCell c = new BaseCell ();
407 Assert.AreEqual (-1, c.RowIndex, "A1");
409 DataGridView dgv = new DataGridView ();
410 dgv.Columns.Add ("hi", "there");
412 DataGridViewRow row = new DataGridViewRow ();
416 Assert.AreEqual (0, dgv.Rows[0].Cells[0].RowIndex, "A2");
420 public void Selected ()
422 DataGridViewCell c = new BaseCell ();
423 Assert.AreEqual (false, c.Selected, "A1");
425 DataGridView dgv = new DataGridView ();
426 dgv.Columns.Add ("hi", "there");
428 DataGridViewRow row = new DataGridViewRow ();
432 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Selected, "A2");
434 dgv.Columns[0].Selected = true;
435 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Selected, "A3");
437 dgv.Rows[0].Selected = true;
438 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Selected, "A4");
440 dgv.Rows[0].Cells[0].Selected = false;
441 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Selected, "A5");
443 dgv.Rows[0].Selected = false;
444 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Selected, "A6");
446 dgv.Rows[0].Cells[0].Selected = true;
447 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Selected, "A7");
450 /* The height of a cell (row) is based on Font
454 DataGridViewCell c = new BaseCell ();
455 Assert.AreEqual (new Size (-1, -1), c.Size, "A1");
457 DataGridView dgv = new DataGridView ();
458 dgv.Columns.Add ("hi", "there");
460 DataGridViewRow row = new DataGridViewRow ();
464 Assert.AreEqual (new Size (100, 22), dgv.Rows[0].Cells[0].Size, "A2");
466 // Does not resize to content
467 dgv.Rows[0].Cells[0].Value = "bob";
468 Assert.AreEqual (new Size (100, 22), dgv.Rows[0].Cells[0].Size, "A3");
475 DataGridViewCell c = new BaseCell ();
476 Assert.AreEqual (DataGridViewContentAlignment.NotSet, c.Style.Alignment, "A1");
477 Assert.AreEqual (Color.Empty, c.Style.BackColor, "A2");
478 Assert.AreEqual (DBNull.Value, c.Style.DataSourceNullValue, "A3");
479 Assert.AreEqual (null, c.Style.Font, "A4");
480 Assert.AreEqual (Color.Empty, c.Style.ForeColor, "A5");
481 Assert.AreEqual (string.Empty, c.Style.Format, "A6");
482 Assert.AreEqual (Thread.CurrentThread.CurrentCulture, c.Style.FormatProvider, "A7");
483 Assert.AreEqual (true, c.Style.IsDataSourceNullValueDefault, "A8");
484 Assert.AreEqual (true, c.Style.IsFormatProviderDefault, "A9");
485 Assert.AreEqual (true, c.Style.IsNullValueDefault, "A10");
486 Assert.AreEqual (string.Empty, c.Style.NullValue, "A11");
487 Assert.AreEqual (Padding.Empty, c.Style.Padding, "A12");
488 Assert.AreEqual (Color.Empty, c.Style.SelectionBackColor, "A13");
489 Assert.AreEqual (Color.Empty, c.Style.SelectionForeColor, "A14");
490 Assert.AreEqual (null, c.Style.Tag, "A15");
491 Assert.AreEqual (DataGridViewTriState.NotSet, c.Style.WrapMode, "A16");
493 DataGridView dgv = new DataGridView ();
494 dgv.Columns.Add ("hi", "there");
496 DataGridViewRow row = new DataGridViewRow ();
500 // Style does not change based on parent
501 // (InheritedStyle does)
502 Assert.AreEqual (DataGridViewContentAlignment.NotSet, c.Style.Alignment, "A17");
503 Assert.AreEqual (Color.Empty, c.Style.BackColor, "A18");
504 Assert.AreEqual (DBNull.Value, c.Style.DataSourceNullValue, "A19");
505 Assert.AreEqual (null, c.Style.Font, "A20");
506 Assert.AreEqual (Color.Empty, c.Style.ForeColor, "A21");
507 Assert.AreEqual (string.Empty, c.Style.Format, "A22");
508 Assert.AreEqual (Thread.CurrentThread.CurrentCulture, c.Style.FormatProvider, "A23");
509 Assert.AreEqual (true, c.Style.IsDataSourceNullValueDefault, "A24");
510 Assert.AreEqual (true, c.Style.IsFormatProviderDefault, "A25");
511 Assert.AreEqual (true, c.Style.IsNullValueDefault, "A26");
512 Assert.AreEqual (string.Empty, c.Style.NullValue, "A27");
513 Assert.AreEqual (Padding.Empty, c.Style.Padding, "A28");
514 Assert.AreEqual (Color.Empty, c.Style.SelectionBackColor, "A29");
515 Assert.AreEqual (Color.Empty, c.Style.SelectionForeColor, "A30");
516 Assert.AreEqual (null, c.Style.Tag, "A31");
517 Assert.AreEqual (DataGridViewTriState.NotSet, c.Style.WrapMode, "A32");
523 DataGridViewCell c = new BaseCell ();
524 Assert.AreEqual (null, c.Tag, "A1");
526 DataGridView dgv = new DataGridView ();
527 dgv.Columns.Add ("hi", "there");
529 DataGridViewRow row = new DataGridViewRow ();
533 Assert.AreEqual (null, dgv.Rows[0].Cells[0].Tag, "A2");
535 dgv.Rows[0].Cells[0].Tag = "bob";
536 Assert.AreEqual ("bob", dgv.Rows[0].Cells[0].Tag, "A3");
540 public void ToolTipText ()
542 DataGridViewCell c = new BaseCell ();
543 Assert.AreEqual (string.Empty, c.ToolTipText, "A1");
545 DataGridView dgv = new DataGridView ();
546 dgv.Columns.Add ("hi", "there");
548 DataGridViewRow row = new DataGridViewRow ();
552 Assert.AreEqual (string.Empty, dgv.Rows[0].Cells[0].ToolTipText, "A2");
554 dgv.Rows[0].Cells[0].ToolTipText = "bob";
555 Assert.AreEqual ("bob", dgv.Rows[0].Cells[0].ToolTipText, "A3");
559 public void Value2 ()
561 DataGridViewCell c = new BaseCell ();
562 Assert.AreEqual (null, c.Value, "A1");
564 DataGridView dgv = new DataGridView ();
565 dgv.Columns.Add ("hi", "there");
567 DataGridViewRow row = new DataGridViewRow ();
571 Assert.AreEqual (null, dgv.Rows[0].Cells[0].Value, "A2");
573 dgv.Rows[0].Cells[0].Value = "bob";
574 Assert.AreEqual ("bob", dgv.Rows[0].Cells[0].Value, "A3");
578 public void ValueType ()
580 DataGridViewCell c = new BaseCell ();
581 Assert.AreEqual (typeof (Image), c.ValueType, "A1");
583 DataGridView dgv = new DataGridView ();
584 dgv.Columns.Add ("hi", "there");
586 DataGridViewRow row = new DataGridViewRow ();
590 Assert.AreEqual (typeof (Image), dgv.Rows[0].Cells[0].ValueType, "A2");
592 dgv.Rows[0].Cells[0].ValueType = typeof (bool);
593 Assert.AreEqual (typeof (bool), dgv.Rows[0].Cells[0].ValueType, "A3");
597 public void Visible ()
599 DataGridViewCell c = new BaseCell ();
600 Assert.AreEqual (false, c.Visible, "A1");
602 DataGridView dgv = new DataGridView ();
603 dgv.Columns.Add ("hi", "there");
605 DataGridViewRow row = new DataGridViewRow ();
609 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Visible, "A2");
611 dgv.Columns[0].Visible = false;
612 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Visible, "A3");
614 dgv.Columns[0].Visible = true;
615 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Visible, "A4");
617 dgv.Rows[0].Visible = false;
618 Assert.AreEqual (false, dgv.Rows[0].Cells[0].Visible, "A5");
620 dgv.Rows[0].Visible = true;
621 Assert.AreEqual (true, dgv.Rows[0].Cells[0].Visible, "A6");
625 public void MethodBorderWidths ()
627 BaseCell c = new BaseCell ();
629 DataGridViewAdvancedBorderStyle style = new DataGridViewAdvancedBorderStyle ();
630 style.Bottom = DataGridViewAdvancedCellBorderStyle.Inset;
631 style.Left = DataGridViewAdvancedCellBorderStyle.InsetDouble;
632 style.Top = DataGridViewAdvancedCellBorderStyle.None;
633 //style.Right = DataGridViewAdvancedCellBorderStyle.NotSet;
635 Assert.AreEqual (new Rectangle (2, 0, 0, 1), c.PublicBorderWidths (style), "A1");
637 style.Bottom = DataGridViewAdvancedCellBorderStyle.Outset;
638 style.Left = DataGridViewAdvancedCellBorderStyle.OutsetDouble;
639 style.Right = DataGridViewAdvancedCellBorderStyle.OutsetPartial;
640 style.Top = DataGridViewAdvancedCellBorderStyle.Single;
642 Assert.AreEqual (new Rectangle (2, 1, 1, 1), c.PublicBorderWidths (style), "A2");
644 DataGridView dgv = new DataGridView ();
645 dgv.Columns.Add ("hi", "there");
647 DataGridViewRow row = new DataGridViewRow ();
651 dgv.Rows[0].DividerHeight = 3;
652 dgv.Columns[0].DividerWidth = 5;
654 Assert.AreEqual (new Rectangle (2, 1, 6, 4), (dgv.Rows[0].Cells[0] as BaseCell).PublicBorderWidths (style), "A3");
657 /* Font measurement dependent
659 public void MethodGetContentBounds ()
661 DataGridViewCell c = new BaseCell ();
662 Assert.AreEqual (Rectangle.Empty, c.GetContentBounds (c.RowIndex), "A1");
663 c.Value = "hello there";
665 DataGridView dgv = new DataGridView ();
666 dgv.Columns.Add ("hi", "there");
668 DataGridViewRow row = new DataGridViewRow ();
672 Assert.AreEqual (new Rectangle (0, 2, 14, 16), dgv.Rows[0].Cells[0].GetContentBounds (dgv.Rows[0].Cells[0].RowIndex), "A2");
674 dgv.Rows[0].Cells[0].Value = new Bitmap (20, 20);
675 Assert.AreEqual (new Rectangle (0, 0, 20, 20), dgv.Rows[0].Cells[0].GetContentBounds (dgv.Rows[0].Cells[0].RowIndex), "A3");
677 dgv.Rows[0].Cells[0].Value = new Bitmap (32, 32);
678 Assert.AreEqual (new Rectangle (0, -5, 32, 32), dgv.Rows[0].Cells[0].GetContentBounds (dgv.Rows[0].Cells[0].RowIndex), "A3");
682 public void MethodGetContentBoundsOverload ()
684 Bitmap b = new Bitmap (1, 1);
685 Graphics g = Graphics.FromImage (b);
687 BaseCell c = new BaseCell ();
688 Assert.AreEqual (Rectangle.Empty, c.PublicGetContentBounds (g, c.Style, c.RowIndex), "A1");
690 DataGridView dgv = new DataGridView ();
691 dgv.Columns.Add ("hi", "there");
693 DataGridViewRow row = new DataGridViewRow ();
697 Assert.AreEqual (new Rectangle (0, 2, 14, 16), (dgv.Rows[0].Cells[0] as BaseCell).PublicGetContentBounds (g, dgv.Rows[0].Cells[0].InheritedStyle, dgv.Rows[0].Cells[0].RowIndex), "A2");
704 public void MethodGetErrorIconBounds ()
706 Bitmap b = new Bitmap (1, 1);
707 Graphics g = Graphics.FromImage (b);
709 BaseCell c = new BaseCell ();
710 Assert.AreEqual (Rectangle.Empty, c.PublicGetErrorIconBounds (g, c.Style, c.RowIndex), "A1");
712 DataGridView dgv = new DataGridView ();
713 dgv.Columns.Add ("hi", "there");
715 DataGridViewRow row = new DataGridViewRow ();
719 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");
725 public void MethodGetErrorText ()
727 Bitmap b = new Bitmap (1, 1);
728 Graphics g = Graphics.FromImage (b);
730 BaseCell c = new BaseCell ();
731 Assert.AreEqual (string.Empty, c.PublicGetErrorText (c.RowIndex), "A1");
733 DataGridView dgv = new DataGridView ();
734 dgv.Columns.Add ("hi", "there");
736 DataGridViewRow row = new DataGridViewRow ();
740 Assert.AreEqual (string.Empty, (dgv.Rows[0].Cells[0] as BaseCell).PublicGetErrorText (dgv.Rows[0].Cells[0].RowIndex), "A2");
746 public void MethodKeyEntersEditMode ()
748 string result = string.Empty;
749 string expected = string.Empty;
751 DataGridViewCell c = new BaseCell ();
753 foreach (Keys k in Enum.GetValues (typeof (Keys)))
754 if (c.KeyEntersEditMode (new KeyEventArgs (k)))
755 result += ((int)k).ToString () + ";";
757 Assert.AreEqual (expected, result, "A1");
759 DataGridView dgv = new DataGridView ();
760 dgv.Columns.Add ("hi", "there");
762 DataGridViewRow row = new DataGridViewRow ();
766 result = string.Empty;
768 foreach (Keys k in Enum.GetValues (typeof (Keys)))
769 if (dgv.Rows[0].Cells[0].KeyEntersEditMode (new KeyEventArgs (k)))
770 result += ((int)k).ToString () + ";";
772 Assert.AreEqual (expected, result, "A2");
774 result = string.Empty;
775 dgv.EditMode = DataGridViewEditMode.EditOnEnter;
777 foreach (Keys k in Enum.GetValues (typeof (Keys)))
778 if (dgv.Rows[0].Cells[0].KeyEntersEditMode (new KeyEventArgs (k)))
779 result += ((int)k).ToString () + ";";
781 Assert.AreEqual (expected, result, "A3");
783 result = string.Empty;
784 dgv.EditMode = DataGridViewEditMode.EditOnF2;
786 foreach (Keys k in Enum.GetValues (typeof (Keys)))
787 if (dgv.Rows[0].Cells[0].KeyEntersEditMode (new KeyEventArgs (k)))
788 result += ((int)k).ToString () + ";";
790 Assert.AreEqual (expected, result, "A4");
792 result = string.Empty;
793 dgv.EditMode = DataGridViewEditMode.EditOnKeystroke;
795 foreach (Keys k in Enum.GetValues (typeof (Keys)))
796 if (dgv.Rows[0].Cells[0].KeyEntersEditMode (new KeyEventArgs (k)))
797 result += ((int)k).ToString () + ";";
799 Assert.AreEqual (expected, result, "A5");
801 result = string.Empty;
802 dgv.EditMode = DataGridViewEditMode.EditProgrammatically;
804 foreach (Keys k in Enum.GetValues (typeof (Keys)))
805 if (dgv.Rows[0].Cells[0].KeyEntersEditMode (new KeyEventArgs (k)))
806 result += ((int)k).ToString () + ";";
808 Assert.AreEqual (expected, result, "A6");
812 public void MethodParseFormattedValue ()
814 DataGridViewCell c = new FormattedBaseCell ();
815 c.ValueType = typeof (bool);
817 BooleanConverter bc = new BooleanConverter ();
818 StringConverter sc = new StringConverter ();
820 object o = c.ParseFormattedValue ("true", c.Style, sc, bc);
821 Assert.AreEqual (true, (bool)o, "A1");
825 public void MethodGetInheritedContextMenuStrip ()
827 DataGridViewCell c = new BaseCell ();
828 Assert.AreEqual (null, c.GetInheritedContextMenuStrip (c.RowIndex), "A1");
830 DataGridView dgv = new DataGridView ();
831 dgv.Columns.Add ("hi", "there");
833 DataGridViewRow row = new DataGridViewRow ();
837 Assert.AreEqual (null, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A2");
839 ContextMenuStrip cms1 = new ContextMenuStrip ();
840 cms1.Items.Add ("Moose");
841 dgv.ContextMenuStrip = cms1;
843 Assert.AreSame (cms1, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A3");
845 ContextMenuStrip cms2 = new ContextMenuStrip ();
846 cms2.Items.Add ("Moose");
847 dgv.Columns[0].ContextMenuStrip = cms2;
849 Assert.AreSame (cms2, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A4");
851 dgv.Rows[0].ContextMenuStrip = cms1;
852 Assert.AreSame (cms1, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A5");
854 dgv.Rows[0].Cells[0].ContextMenuStrip = cms2;
855 Assert.AreSame (cms2, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A6");
858 private class FormattedBaseCell : DataGridViewImageCell
860 public override Type FormattedValueType { get { return typeof (string); } }
863 private class BaseCell : DataGridViewImageCell
865 public Rectangle PublicGetContentBounds (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex)
866 { return GetContentBounds (graphics, cellStyle, rowIndex); }
867 public Rectangle PublicGetErrorIconBounds (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex)
868 { return GetErrorIconBounds (graphics, cellStyle, rowIndex); }
869 public string PublicGetErrorText (int rowIndex)
870 { return GetErrorText (rowIndex); }
871 public Rectangle PublicBorderWidths (DataGridViewAdvancedBorderStyle advancedBorderStyle)
872 { return BorderWidths (advancedBorderStyle); }