Link to home
Start Free TrialLog in
Avatar of TrialUser
TrialUserFlag for Afghanistan

asked on

dynamically set datagridview row height

I display some text in of the field in the datagridview. Is it possible to increase the row height only to the rows where this field wraps to the second line. That is whenever the text is longer and cant be displayed in one line it gets wrapped and displayed in two lines in the cell.

How can I detect this and increase the row height. Thanks. Please help.
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

After populating the grid code, add this code:
for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
{
this.dataGridView1.AutoResizeRow(i);
}

or  set your grid AutoSizeRowsMode property to:
AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.DisplayedCells

Can you tell me what AutoSizeRowsMode  property is set on your grid?
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewautosizerowsmode.aspx
Avatar of TrialUser

ASKER

If I set the Autoresize to DisplayedCells,  the rows  are  getting autoresized. However I have set the Height of the Rows in the RowTemplate to say 50. Iwouldlike for therows to have this as theminimum height. Only in thecases when the text wraps to thesecond line, I would like for the row to have autoresize property. In other words is it possible to set minimum height for the rows?

Thanks
Ok, this is an additional requirement to your question:
DataGridViewRow has a property MinimumHeight that maintains the display of the row by setting a limit to how far the user can resize the row's height through the user interface (UI).
ASKER CERTIFIED SOLUTION
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial