在运行时设置DataGridView行的高度 [英] Setting Height of DataGridView Rows at Run time

查看:305
本文介绍了在运行时设置DataGridView行的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

在程序中,我需要在运行时更改DataGridView每行的高度.我使用了下面的代码,但我想知道为什么它不起作用?你能让我怎样完成它吗?

非常感谢您

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;
            }

推荐答案

它对我有用,除非...


...您不会先设置行高,然后再更改数据,对吗?
因为
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");

会给您三行,然后是一小行.
但是你不会那样做,对吗? :laugh:

Will give you three big rows, then one small one.
But you wouldn''t do that, would you? :laugh:


这篇关于在运行时设置DataGridView行的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆