Click here to Skip to main content
15,867,756 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

In a program I need to change the height of each rows of DataGridView at run time. I used the code below but I wonder why it does not work? Could you please let me how I can get it done?

Thank you very much

int intCount = dataGridView1.RowCount ;

            for (int i = 0; i < intCount; i++)
            {
                dataGridView1.Rows[i].Height = 30;
            }
Posted

1 solution

It works for me, unless...


...You wouldn't be setting the row height, then changing the data, would you?
Because
dataGridView1.Columns.Add("C1", "Col1");
dataGridView1.Columns.Add("C2", "Col2");
dataGridView1.Columns.Add("C3", "Col3");
dataGridView1.Rows.Add("R1C1", "R1C2", "R1C3");
dataGridView1.Rows.Add("R2C1", "R2C2", "R2C3");
dataGridView1.Rows.Add("R3C1", "R3C2", "R3C3");
int intCount = dataGridView1.RowCount;

for (int i = 0; i < intCount; i++)
    {
    dataGridView1.Rows[i].Height = 40;
    }
dataGridView1.Rows.Add("R4C1", "R4C2", "R4C3");
Will give you three big rows, then one small one.
But you wouldn't do that, would you? :laugh:
 
Share this answer
 
Comments
ahhashemi 25-Jul-10 4:04am    
Reason for my vote of 4
For being helpfull

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900