1 // Copyright (c) 2014 SIL International
2 // This software is licensed under the MIT License (http://opensource.org/licenses/MIT)
4 using System.Windows.Forms;
6 using CategoryAttribute = NUnit.Framework.CategoryAttribute;
8 namespace MonoTests.System.Windows.Forms
11 public class DataGridViewRowHeightInfoNeededEventArgsTests
15 public RowInfo (DataGridViewRowHeightInfoNeededEventArgs e)
18 MinimumHeight = e.MinimumHeight;
22 public int MinimumHeight;
25 class DummyDataGridView : DataGridView
27 public RowInfo RowInfo;
29 protected override void OnRowHeightInfoNeeded (DataGridViewRowHeightInfoNeededEventArgs e)
31 base.OnRowHeightInfoNeeded (e);
32 RowInfo = new RowInfo (e);
37 [Category("NotWorking")]
38 public void HeightCantBeLessThanCurrentMinimumHeight ()
40 using (var dgv = new DummyDataGridView ()) {
42 dgv.VirtualMode = true;
44 dgv.Rows [0].MinimumHeight = 5;
45 dgv.Rows [0].Height = 10;
46 dgv.RowHeightInfoNeeded += (sender, e) => {
50 dgv.UpdateRowHeightInfo (0, false);
52 // Execute - this triggers the RowHeightInfoNeeded event
53 // This test doesn't work because of different implementation details in .NET
54 // and Mono: on .NET RowHeightInfoNeeded gets called for the first time when
55 // executing the following line. In Mono RowHeightInfoNeeded got already called
56 // while executing dgv.UpdateRowHeightInfo. This means that when RowHeightInfoNeeded
57 // gets called now MinimumHeight is already set to 2, allowing Height to become
59 // On .NET since it is the first time Height will be set to 5 (the current
60 // MinimumHeight value).
61 // The .NET behaviour is surprising since the order of setting the information
62 // in RowHeightInfoNeeded shouldn't matter, therefore I don't think it's worth
63 // changing the behaviour in Mono. Even more so since there is an easy
64 // workaround: simply swapping the two lines in the RowHeighInfoNeeded event
65 // handler works around the problem.
66 var dummy = dgv.Rows [0].Height;
69 var rowHeightInfo = dgv.RowInfo;
70 Assert.AreEqual (5, rowHeightInfo.Height, "#A1"); // 5 because of buggy .NET behaviour
71 Assert.AreEqual (2, rowHeightInfo.MinimumHeight, "#A2");
76 public void SettingHeightAfterChangingMinimumHeight ()
78 using (var dgv = new DummyDataGridView ()) {
80 dgv.VirtualMode = true;
82 dgv.Rows [0].MinimumHeight = 5;
83 dgv.Rows [0].Height = 10;
84 dgv.RowHeightInfoNeeded += (sender, e) => {
88 dgv.UpdateRowHeightInfo (0, false);
90 // Execute - this triggers the RowHeightInfoNeeded event
91 var dummy = dgv.Rows [0].Height;
94 var rowHeightInfo = dgv.RowInfo;
95 Assert.AreEqual (2, rowHeightInfo.Height, "#B1");
96 Assert.AreEqual (2, rowHeightInfo.MinimumHeight, "#B2");