Hi,

I am having a lot of difficulties with the DataGridView control in Windows Forms. No matter what I do, I can not affect the height of rows in any way, shape, or form. I try to set the grid's properties so that it will automatically resize to row contents, but it does nothing. In addition, trying to directly set the row's height does nothing. Even when I check off the option to allow the user to resize the row, when the program is running there are no handles for the user to do any resizing.

No matter what I do the rows are stuck at their default height no matter what I try to do to them or put in them. For reference, my rows are being added programatically with the AddRow method.

Any help is greatly appreciated.

Row height:

foreach (DataGridViewRow row in dataGridView1.Rows)
     row.Height = 30;

This an example if you allow users to add rows, so even a new row will have the "default" height:

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            dataGridView1.Columns.Add("col1", "Column1");
            dataGridView1.AllowUserToAddRows = true;

            //example data to populate:
            for (int i = 0; i < 10; i++)
                dataGridView1.Rows.Add("Cell " + i + 1);
            ResizeRows();
            //creating event for adding new rows:
            dataGridView1.RowsAdded+=new DataGridViewRowsAddedEventHandler(dataGridView1_RowsAdded);
        }

        public void ResizeRows()
        {
            foreach (DataGridViewRow row in dataGridView1.Rows)
                row.Height = 30;
        }

        private void dataGridView1_RowsAdded(object obj, DataGridViewRowsAddedEventArgs e)
        {
            ResizeRows();
        }
    }

Hope it helps a bit,
Mitja

Hi,

As I tried to say adjusting the height property doesn't do anything. I'm at a loss as to what the problem is.

Sure it does. Check if you dont have any other code some place else. Delete dgv from the form (this will delete all its code) and put it back on the form (in form designer). And thats it - do nothing more. Use my code and it has to work - it did wok for sure for me.
Calling "ResizeRows()" method has to resize all the rows height to the wanted value (in my example is 30).
Hope it helps,
Mitja

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.