InvalidateRow (i);
}
+ private void UpdateRowHeightInfo (DataGridViewRow row)
+ {
+ DataGridViewRowHeightInfoNeededEventArgs rowInfo =
+ new DataGridViewRowHeightInfoNeededEventArgs (row.Index, row.Height, row.MinimumHeight);
+ OnRowHeightInfoNeeded (rowInfo);
+
+ if (row.Height != rowInfo.Height || row.MinimumHeight != rowInfo.MinimumHeight) {
+ row.MinimumHeight = rowInfo.MinimumHeight;
+ row.Height = rowInfo.Height;
+ OnRowHeightInfoPushed (new DataGridViewRowHeightInfoPushedEventArgs (row.Index, rowInfo.Height,
+ rowInfo.MinimumHeight));
+ }
+ }
+
public void UpdateRowHeightInfo (int rowIndex, bool updateToEnd)
{
if (rowIndex < 0 && updateToEnd)
if (updateToEnd) {
for (int i = rowIndex; i < Rows.Count; i++) {
- DataGridViewRow row = Rows[i];
- if (!row.Visible)
- continue;
-
- DataGridViewRowHeightInfoNeededEventArgs rowInfo =
- new DataGridViewRowHeightInfoNeededEventArgs (row.Index, row.Height, row.MinimumHeight);
- OnRowHeightInfoNeeded (rowInfo);
-
- if (row.Height != rowInfo.Height || row.MinimumHeight != rowInfo.MinimumHeight) {
- row.Height = rowInfo.Height;
- row.MinimumHeight = rowInfo.MinimumHeight;
- OnRowHeightInfoPushed (new DataGridViewRowHeightInfoPushedEventArgs (row.Index, rowInfo.Height,
- rowInfo.MinimumHeight));
- }
+ DataGridViewRow row = Rows [i];
+ if (row.Visible)
+ UpdateRowHeightInfo (row);
}
} else {
- DataGridViewRow row = Rows[rowIndex];
- DataGridViewRowHeightInfoNeededEventArgs rowInfo =
- new DataGridViewRowHeightInfoNeededEventArgs (row.Index, row.Height, row.MinimumHeight);
- OnRowHeightInfoNeeded (rowInfo);
-
- if (row.Height != rowInfo.Height || row.MinimumHeight != rowInfo.MinimumHeight) {
- row.Height = rowInfo.Height;
- row.MinimumHeight = rowInfo.MinimumHeight;
- OnRowHeightInfoPushed (new DataGridViewRowHeightInfoPushedEventArgs (row.Index, rowInfo.Height,
- rowInfo.MinimumHeight));
- }
+ UpdateRowHeightInfo (Rows [rowIndex]);
}
}
if (height != value) {
if (value < minimumHeight) {
- throw new ArgumentOutOfRangeException("Height can't be less than MinimumHeight.");
+ height = minimumHeight;
+ } else {
+ height = value;
}
- height = value;
if (DataGridView != null) {
DataGridView.Invalidate ();
DataGridView.OnRowHeightChanged(new DataGridViewRowEventArgs(this));
if (value < 2 || value > Int32.MaxValue) {
throw new ArgumentOutOfRangeException("MinimumHeight should be between 2 and Int32.MaxValue.");
}
+ if (height < value) {
+ // don't let height get less than minimumHeight!
+ Height = value;
+ }
minimumHeight = value;
if (DataGridView != null) {
DataGridView.OnRowMinimumHeightChanged(new DataGridViewRowEventArgs(this));
public int Height {
get { return height; }
- set { height = value; }
+ set { height = value < minimumHeight ? minimumHeight : value; }
}
public int MinimumHeight {
System.Windows.Forms/DataGridViewImageCellTest.cs
System.Windows.Forms/DataGridViewRowCollectionTest.cs
System.Windows.Forms/DataGridViewRowHeaderTest.cs
+System.Windows.Forms/DataGridViewRowHeightInfoNeededEventArgsTests.cs
System.Windows.Forms/DataGridViewRowTest.cs
System.Windows.Forms/DataGridViewTest.cs
System.Windows.Forms/DataGridViewTextBoxCellTest.cs
--- /dev/null
+// Copyright (c) 2014 SIL International
+// This software is licensed under the MIT License (http://opensource.org/licenses/MIT)
+using System;
+using System.Windows.Forms;
+using NUnit.Framework;
+using CategoryAttribute = NUnit.Framework.CategoryAttribute;
+
+namespace MonoTests.System.Windows.Forms
+{
+ [TestFixture]
+ public class DataGridViewRowHeightInfoNeededEventArgsTests
+ {
+ struct RowInfo
+ {
+ public RowInfo (DataGridViewRowHeightInfoNeededEventArgs e)
+ {
+ Height = e.Height;
+ MinimumHeight = e.MinimumHeight;
+ }
+
+ public int Height;
+ public int MinimumHeight;
+ }
+
+ class DummyDataGridView : DataGridView
+ {
+ public RowInfo RowInfo;
+
+ protected override void OnRowHeightInfoNeeded (DataGridViewRowHeightInfoNeededEventArgs e)
+ {
+ base.OnRowHeightInfoNeeded (e);
+ RowInfo = new RowInfo (e);
+ }
+ }
+
+ [Test]
+ [Category("NotWorking")]
+ public void HeightCantBeLessThanCurrentMinimumHeight ()
+ {
+ using (var dgv = new DummyDataGridView ()) {
+ // Setup
+ dgv.VirtualMode = true;
+ dgv.RowCount = 1;
+ dgv.Rows [0].MinimumHeight = 5;
+ dgv.Rows [0].Height = 10;
+ dgv.RowHeightInfoNeeded += (sender, e) => {
+ e.Height = 2;
+ e.MinimumHeight = 2;
+ };
+ dgv.UpdateRowHeightInfo (0, false);
+
+ // Execute - this triggers the RowHeightInfoNeeded event
+ // This test doesn't work because of different implementation details in .NET
+ // and Mono: on .NET RowHeightInfoNeeded gets called for the first time when
+ // executing the following line. In Mono RowHeightInfoNeeded got already called
+ // while executing dgv.UpdateRowHeightInfo. This means that when RowHeightInfoNeeded
+ // gets called now MinimumHeight is already set to 2, allowing Height to become
+ // 2 as well.
+ // On .NET since it is the first time Height will be set to 5 (the current
+ // MinimumHeight value).
+ // The .NET behaviour is surprising since the order of setting the information
+ // in RowHeightInfoNeeded shouldn't matter, therefore I don't think it's worth
+ // changing the behaviour in Mono. Even more so since there is an easy
+ // workaround: simply swapping the two lines in the RowHeighInfoNeeded event
+ // handler works around the problem.
+ var dummy = dgv.Rows [0].Height;
+
+ // Verify
+ var rowHeightInfo = dgv.RowInfo;
+ Assert.AreEqual (5, rowHeightInfo.Height, "#A1"); // 5 because of buggy .NET behaviour
+ Assert.AreEqual (2, rowHeightInfo.MinimumHeight, "#A2");
+ }
+ }
+
+ [Test]
+ public void SettingHeightAfterChangingMinimumHeight ()
+ {
+ using (var dgv = new DummyDataGridView ()) {
+ // Setup
+ dgv.VirtualMode = true;
+ dgv.RowCount = 1;
+ dgv.Rows [0].MinimumHeight = 5;
+ dgv.Rows [0].Height = 10;
+ dgv.RowHeightInfoNeeded += (sender, e) => {
+ e.MinimumHeight = 2;
+ e.Height = 2;
+ };
+ dgv.UpdateRowHeightInfo (0, false);
+
+ // Execute - this triggers the RowHeightInfoNeeded event
+ var dummy = dgv.Rows [0].Height;
+
+ // Verify
+ var rowHeightInfo = dgv.RowInfo;
+ Assert.AreEqual (2, rowHeightInfo.Height, "#B1");
+ Assert.AreEqual (2, rowHeightInfo.MinimumHeight, "#B2");
+ }
+ }
+ }
+}
+
}
[Test]
- [Category ("NotWorking")]
- public void MinimumHeight ()
+ public void Height_SetHeightLessThanMinHeightSilentlySetsToMinHeight()
{
- DataGridViewRow row = new DataGridViewRow();
- Assert.IsTrue (row.MinimumHeight > 0, "#A1");
- Assert.IsFalse (row.Height > row.MinimumHeight, "#A2");
- row.MinimumHeight = 40;
- row.Height = 50;
- Assert.AreEqual (40, row.MinimumHeight, "#B1");
- Assert.AreEqual (50, row.Height, "#B2");
- row.MinimumHeight = 20;
- Assert.AreEqual (20, row.MinimumHeight, "#C1");
- Assert.AreEqual (20, row.Height, "#C2");
- row.MinimumHeight = 40;
- Assert.AreEqual (40, row.MinimumHeight, "#D1");
- Assert.AreEqual (40, row.Height, "#D2");
+ using (var row = new DataGridViewRow ()) {
+ // Setup
+ row.MinimumHeight = 5;
+
+ // Execute
+ row.Height = 2;
+
+ // Verify
+ Assert.AreEqual (5, row.Height, "Height didn't get set to MinimumHeight");
+ }
+ }
+
+ [Test]
+ public void MinimumHeight_DefaultValues ()
+ {
+ using (DataGridViewRow row = new DataGridViewRow ()) {
+ Assert.IsTrue (row.MinimumHeight > 0, "#A1");
+ Assert.IsTrue (row.Height >= row.MinimumHeight, "#A2");
+ }
+ }
+
+ [Test]
+ public void MinimumHeight_SetValues ()
+ {
+ using (DataGridViewRow row = new DataGridViewRow ()) {
+ row.MinimumHeight = 40;
+ row.Height = 50;
+ Assert.AreEqual (40, row.MinimumHeight, "#B1");
+ Assert.AreEqual (50, row.Height, "#B2");
+ }
+ }
+
+ [Test]
+ public void MinimumHeight_IncreaseMinHeightChangesHeight ()
+ {
+ using (DataGridViewRow row = new DataGridViewRow ()) {
+ row.MinimumHeight = 20;
+ row.Height = 20;
+ Assert.AreEqual (20, row.MinimumHeight, "#C1");
+ Assert.AreEqual (20, row.Height, "#C2");
+ row.MinimumHeight = 40;
+ Assert.AreEqual (40, row.MinimumHeight, "#D1");
+ Assert.AreEqual (40, row.Height, "#D2");
+ }
+ }
+
+ [Test]
+ [ExpectedException(typeof(ArgumentOutOfRangeException))]
+ public void MinimumHeight_SettingToLessThan2ThrowsException ()
+ {
+ using (DataGridViewRow row = new DataGridViewRow ()) {
+ // We expect the next line to throw an ArgumentOutOfRangeException
+ row.MinimumHeight = 1;
+ }
}
-
-
-
[Test]
[NUnit.Framework.Category ("NotWorking")] // DGVComboBox not implemented
Assert.IsNull (dgvr2.DataGridView, "#5");
Assert.IsNull (dgvr3.DataGridView, "#6");
}
+
+ [Test] // Xamarin bug #2394
+ public void Bug2394_RowHeightLessThanOldMinHeightVirtMode ()
+ {
+ using (var dgv = new DataGridView ()) {
+ dgv.VirtualMode = true;
+ dgv.RowCount = 1;
+ dgv.Rows [0].MinimumHeight = 5;
+ dgv.Rows [0].Height = 10;
+ dgv.RowHeightInfoNeeded += (sender, e) => {
+ // NOTE: the order is important here.
+ e.MinimumHeight = 2;
+ e.Height = 2;
+ };
+ dgv.UpdateRowHeightInfo (0, false);
+ Assert.AreEqual (2, dgv.Rows [0].Height);
+ Assert.AreEqual (2, dgv.Rows [0].MinimumHeight);
+ }
+ }
+
+ [Test] // Xamarin bug #2394
+ public void Bug2394_RowHeightLessThanMinHeightVirtMode ()
+ {
+ using (var dgv = new DataGridView ()) {
+ dgv.VirtualMode = true;
+ dgv.RowCount = 1;
+ dgv.Rows [0].Height = 10;
+ dgv.Rows [0].MinimumHeight = 5;
+ dgv.RowHeightInfoNeeded += (sender, e) => {
+ // Setting the height to a value less than the minimum height
+ // will be silently ignored and instead set to MinimumHeight.
+ e.Height = 2;
+ };
+ dgv.UpdateRowHeightInfo (0, false);
+ Assert.AreEqual(5, dgv.Rows[0].Height);
+ Assert.AreEqual(5, dgv.Rows[0].MinimumHeight);
+ }
+ }
+
+ [Test] // Xamarin bug #2394
+ public void Bug2394_MinHeightGreaterThanOldRowHeightVirtMode ()
+ {
+ using (var dgv = new DataGridView ()) {
+ dgv.VirtualMode = true;
+ dgv.RowCount = 1;
+ dgv.Rows [0].Height = 10;
+ dgv.Rows [0].MinimumHeight = 5;
+ dgv.RowHeightInfoNeeded += (sender, e) => {
+ e.MinimumHeight = 30;
+ e.Height = 40;
+ };
+ dgv.UpdateRowHeightInfo (0, false);
+ Assert.AreEqual (40, dgv.Rows [0].Height);
+ Assert.AreEqual (30, dgv.Rows [0].MinimumHeight);
+ }
+ }
}
[TestFixture]