I'm having difficulties setting the row heights in the DataGridView control. I'm currently using the control in non-Databound mode (I started using a Dataset but stopped using it due to similar difficulties).
I'm displaying multi-line text data. Each cell is set to have a WrapMode of true through the various default style mechanisms. Initially, I started with AutoSizeRowsMode set to AllCells and no specific code to size rows. I found that the result was too slow and tried switching to an AutoSizeRowsMode of Displayed Cells. I found that the row heights didn't match their multi-line content so I tried to AutoResizeRow the rows after they were added andfound no change. I've tried programmatically setting the Row height using "(mainDataGridView.Rows[mainDataGridView.Rows.Count - 1]).Height = height;". This also didn't change the row height.
In case it's relevant,when I've finished adding rows, I set the CurrentCell to be the last row but the last row isn't visible; it's a few rows further down than the last visible row. I've also noticed that when AutoResizeMode is set to DisplayedCells and I display 200 rows of test data, the heights of rows 182-193 seem to have appropriate heights while the others are smaller than they should be,
Any suggestions?
Also, can anyone explain why DataGridView row sizing is affected by which rows are displayed? It would seem that the row height would (normally anyway) be the Y component of the tallest cell in the row's Preferred size.
Thanks
Mike
In case it helps, here's the DataGridView configuration generated by the Designer.
System.Windows.Forms.
DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.
DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
this.mainDataGridView = new System.Windows.Forms.DataGridView();
((System.ComponentModel.
ISupportInitialize)(this.mainDataGridView)).BeginInit();
this.SuspendLayout();
//
// mainDataGridView
//
this.mainDataGridView.AllowUserToAddRows = false;
this.mainDataGridView.AllowUserToDeleteRows = false;
this.mainDataGridView.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.DisplayedCells;
this.mainDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridViewCellStyle1.Alignment = System.Windows.Forms.
DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle1.BackColor = System.Drawing.
SystemColors.Window;
dataGridViewCellStyle1.Font =
new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
dataGridViewCellStyle1.ForeColor = System.Drawing.
SystemColors.ControlText;
dataGridViewCellStyle1.SelectionBackColor = System.Drawing.
SystemColors.Highlight;
dataGridViewCellStyle1.SelectionForeColor = System.Drawing.
SystemColors.HighlightText;
dataGridViewCellStyle1.WrapMode = System.Windows.Forms.
DataGridViewTriState.True;
this.mainDataGridView.DefaultCellStyle = dataGridViewCellStyle1;
this.mainDataGridView.Location = new System.Drawing.Point(18, 12);
this.mainDataGridView.Name = "mainDataGridView";
this.mainDataGridView.ReadOnly = true;
dataGridViewCellStyle2.WrapMode = System.Windows.Forms.
DataGridViewTriState.True;
this.mainDataGridView.RowsDefaultCellStyle = dataGridViewCellStyle2;
this.mainDataGridView.RowTemplate.DefaultCellStyle.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.mainDataGridView.RowTemplate.Resizable = System.Windows.Forms.DataGridViewTriState.False;
this.mainDataGridView.Size = new System.Drawing.Size(648, 452);
this.mainDataGridView.TabIndex = 0;