I have encountered a rather nasty problem with the DataGridView
control (Windows.Forms, .NET Framework 3.0) when there is a DataGridViewCell
that is larger than the DataGridView itself. When the large cell is scrolled into view it displays normally, cut off at the bottom since it is larger than the view. If you scroll down further it eventually "snaps" at the top and stays there, until you reach a certain threshold. Then, the next row will be displayed at the top and the "large" row disappears.
Because of that you are never able to fully see the contents of the large cell.
Here's an example code:
using System;
using System.Windows;
namespace LoggerTextBox {
public class TestForm : Form
{
public TestForm()
{
Text = "DataGridView Large Cell Example";
SetBounds(0, 0, 300, 200, BoundsSpecified.Width | BoundsSpecified.Height);
DataGridView dataGridView = new DataGridView();
dataGridView.Dock = DockStyle.Fill;
dataGridView.ScrollBars = ScrollBars.Both;
dataGridView.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders;
Controls.Add(dataGridView);
DataGridViewColumn column = new DataGridViewTextBoxColumn();
column.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
column.CellTemplate.Style.WrapMode = DataGridViewTriState.True;
dataGridView.Columns.Add(column);
// normal row
DataGridViewRow row = new DataGridViewRow();
DataGridViewCell cell = (DataGridViewTextBoxCell)column.CellTemplate.Clone();
cell.Value = "Foo";
row.Cells.Add(cell);
dataGridView.Rows.AddRange(row);
// multiline row
row = new DataGridViewRow();
cell = (DataGridViewTextBoxCell)column.CellTemplate.Clone();
cell.Value =
"Lorem ipsum dolor sit amet, consetetur sadipscing elitr," + Environment.NewLine +
"sed diam nonumy eirmod tempor invidunt ut labore et doloreLorem," + Environment.NewLine +
"ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy," + Environment.NewLine +
"eirmod tempor invidunt ut labore et dolore magna aliquyam erat,," + Environment.NewLine +
"sed diam voluptua. At vero eos et accusam et justo duo dolores et," + Environment.NewLine +
"ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est," + Environment.NewLine +
"Lorem ipsum dolor sit amet. magna aliquyam erat, sed diam voluptua.," + Environment.NewLine +
"At vero eos et accusam et justo duo dolores et ea rebum. Stet clita," + Environment.NewLine +
"kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.";
row.Cells.Add(cell);
dataGridView.Rows.AddRange(row);
// normal row
row = new DataGridViewRow();
cell = (DataGridViewTextBoxCell)column.CellTemplate.Clone();
cell.Value = "Bar";
row.Cells.Add(cell);
dataGridView.Rows.AddRange(row);
}
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new TestForm());
}
}
} // namespace
Any idea how to fix this?