2 // DataGridViewTextBoxCellTest.cs - Unit tests for
3 // System.Windows.Forms.DataGridViewTextBoxCell
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 DataGridViewTextBoxCellTest : TestHelper
48 DataGridViewTextBoxCell tbc = new DataGridViewTextBoxCell ();
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, 11, 0, 0), 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 (null, c.DefaultNewRowValue, "A1");
140 DataGridView dgv = new DataGridView ();
141 dgv.Columns.Add ("hi", "there");
143 DataGridViewRow row = new DataGridViewRow ();
147 Assert.AreEqual (null, dgv.Rows[0].Cells[0].DefaultNewRowValue, "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 (string), 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 = "bob";
336 Assert.AreEqual (new Size (26, 20), dgv.Rows[0].Cells[0].PreferredSize, "A3");
338 dgv.Rows[0].Cells[0].Value = "roasted quail";
339 Assert.AreEqual (new Size (68, 20), dgv.Rows[0].Cells[0].PreferredSize, "A3");
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 (object), c.ValueType, "A1");
583 DataGridView dgv = new DataGridView ();
584 dgv.Columns.Add ("hi", "there");
586 DataGridViewRow row = new DataGridViewRow ();
590 Assert.AreEqual (typeof (object), 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, 3, 56, 15), dgv.Rows[0].Cells[0].GetContentBounds (dgv.Rows[0].Cells[0].RowIndex), "A2");
674 dgv.Rows[0].Cells[0].Value = "whoa whoa whoa whoa";
675 Assert.AreEqual (new Rectangle (0, 3, 94, 15), dgv.Rows[0].Cells[0].GetContentBounds (dgv.Rows[0].Cells[0].RowIndex), "A3");
679 public void MethodGetContentBoundsOverload ()
681 Bitmap b = new Bitmap (1, 1);
682 Graphics g = Graphics.FromImage (b);
684 BaseCell c = new BaseCell ();
685 Assert.AreEqual (Rectangle.Empty, c.PublicGetContentBounds (g, c.Style, c.RowIndex), "A1");
687 DataGridView dgv = new DataGridView ();
688 dgv.Columns.Add ("hi", "there");
690 DataGridViewRow row = new DataGridViewRow ();
694 Assert.AreEqual (new Rectangle (0, 11, 0, 0), (dgv.Rows[0].Cells[0] as BaseCell).PublicGetContentBounds (g, dgv.Rows[0].Cells[0].InheritedStyle, dgv.Rows[0].Cells[0].RowIndex), "A2");
701 public void MethodGetErrorIconBounds ()
703 Bitmap b = new Bitmap (1, 1);
704 Graphics g = Graphics.FromImage (b);
706 BaseCell c = new BaseCell ();
707 Assert.AreEqual (Rectangle.Empty, c.PublicGetErrorIconBounds (g, c.Style, c.RowIndex), "A1");
709 DataGridView dgv = new DataGridView ();
710 dgv.Columns.Add ("hi", "there");
712 DataGridViewRow row = new DataGridViewRow ();
716 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");
722 public void MethodGetErrorText ()
724 Bitmap b = new Bitmap (1, 1);
725 Graphics g = Graphics.FromImage (b);
727 BaseCell c = new BaseCell ();
728 Assert.AreEqual (string.Empty, c.PublicGetErrorText (c.RowIndex), "A1");
730 DataGridView dgv = new DataGridView ();
731 dgv.Columns.Add ("hi", "there");
733 DataGridViewRow row = new DataGridViewRow ();
737 Assert.AreEqual (string.Empty, (dgv.Rows[0].Cells[0] as BaseCell).PublicGetErrorText (dgv.Rows[0].Cells[0].RowIndex), "A2");
743 public void MethodKeyEntersEditMode ()
745 string result = string.Empty;
746 string expected = "32;48;49;50;51;52;53;54;55;56;57;65;66;67;68;69;70;71;72;73;74;75;76;77;78;79;80;81;82;83;84;85;86;87;88;89;90;96;97;98;99;100;101;102;103;104;105;106;107;108;109;110;111;170;181;186;186;187;188;189;190;191;191;192;192;219;219;220;220;221;221;222;222;223;226;226;229;231;246;248;249;250;251;252;253;254;";
748 DataGridViewCell c = new BaseCell ();
750 foreach (Keys k in Enum.GetValues (typeof (Keys)))
751 if (c.KeyEntersEditMode (new KeyEventArgs (k)))
752 result += ((int)k).ToString () + ";";
754 Assert.AreEqual (expected, result, "A1");
756 DataGridView dgv = new DataGridView ();
757 dgv.Columns.Add ("hi", "there");
759 DataGridViewRow row = new DataGridViewRow ();
763 result = string.Empty;
765 foreach (Keys k in Enum.GetValues (typeof (Keys)))
766 if (dgv.Rows[0].Cells[0].KeyEntersEditMode (new KeyEventArgs (k)))
767 result += ((int)k).ToString () + ";";
769 Assert.AreEqual (expected, result, "A2");
771 result = string.Empty;
772 dgv.EditMode = DataGridViewEditMode.EditOnEnter;
774 foreach (Keys k in Enum.GetValues (typeof (Keys)))
775 if (dgv.Rows[0].Cells[0].KeyEntersEditMode (new KeyEventArgs (k)))
776 result += ((int)k).ToString () + ";";
778 Assert.AreEqual (expected, result, "A3");
780 result = string.Empty;
781 dgv.EditMode = DataGridViewEditMode.EditOnF2;
783 foreach (Keys k in Enum.GetValues (typeof (Keys)))
784 if (dgv.Rows[0].Cells[0].KeyEntersEditMode (new KeyEventArgs (k)))
785 result += ((int)k).ToString () + ";";
787 Assert.AreEqual (expected, result, "A4");
789 result = string.Empty;
790 dgv.EditMode = DataGridViewEditMode.EditOnKeystroke;
792 foreach (Keys k in Enum.GetValues (typeof (Keys)))
793 if (dgv.Rows[0].Cells[0].KeyEntersEditMode (new KeyEventArgs (k)))
794 result += ((int)k).ToString () + ";";
796 Assert.AreEqual (expected, result, "A5");
798 result = string.Empty;
799 dgv.EditMode = DataGridViewEditMode.EditProgrammatically;
801 foreach (Keys k in Enum.GetValues (typeof (Keys)))
802 if (dgv.Rows[0].Cells[0].KeyEntersEditMode (new KeyEventArgs (k)))
803 result += ((int)k).ToString () + ";";
805 Assert.AreEqual (expected, result, "A6");
809 public void MethodParseFormattedValue ()
811 DataGridViewCell c = new FormattedBaseCell ();
812 c.ValueType = typeof (bool);
814 BooleanConverter bc = new BooleanConverter ();
815 StringConverter sc = new StringConverter ();
817 object o = c.ParseFormattedValue ("true", c.Style, sc, bc);
818 Assert.AreEqual (true, (bool)o, "A1");
822 public void MethodGetInheritedContextMenuStrip ()
824 DataGridViewCell c = new BaseCell ();
825 Assert.AreEqual (null, c.GetInheritedContextMenuStrip (c.RowIndex), "A1");
827 DataGridView dgv = new DataGridView ();
828 dgv.Columns.Add ("hi", "there");
830 DataGridViewRow row = new DataGridViewRow ();
834 Assert.AreEqual (null, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A2");
836 ContextMenuStrip cms1 = new ContextMenuStrip ();
837 cms1.Items.Add ("Moose");
838 dgv.ContextMenuStrip = cms1;
840 Assert.AreSame (cms1, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A3");
842 ContextMenuStrip cms2 = new ContextMenuStrip ();
843 cms2.Items.Add ("Moose");
844 dgv.Columns[0].ContextMenuStrip = cms2;
846 Assert.AreSame (cms2, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A4");
848 dgv.Rows[0].ContextMenuStrip = cms1;
849 Assert.AreSame (cms1, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A5");
851 dgv.Rows[0].Cells[0].ContextMenuStrip = cms2;
852 Assert.AreSame (cms2, dgv.Rows[0].Cells[0].GetInheritedContextMenuStrip (dgv.Rows[0].Cells[0].RowIndex), "A6");
855 private class FormattedBaseCell : DataGridViewTextBoxCell
857 public override Type FormattedValueType { get { return typeof (string); } }
860 private class BaseCell : DataGridViewTextBoxCell
862 public Rectangle PublicGetContentBounds (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex)
863 { return GetContentBounds (graphics, cellStyle, rowIndex); }
864 public Rectangle PublicGetErrorIconBounds (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex)
865 { return GetErrorIconBounds (graphics, cellStyle, rowIndex); }
866 public string PublicGetErrorText (int rowIndex)
867 { return GetErrorText (rowIndex); }
868 public Rectangle PublicBorderWidths (DataGridViewAdvancedBorderStyle advancedBorderStyle)
869 { return BorderWidths (advancedBorderStyle); }