Add extra column to fill gap in datagridview c #

I have a datagridview that im binding a DataTable to. What I want to do is add an extra column that will fill in the remaining space in the window form. At the moment I only have 3 columns, so the width of all columns is about half the size of the window form.

0


source to share


1 answer


After binding DataTable to DataGridView, set desired AutoSizeMode column to fill.

        DataTable dt = new DataTable("Table1");
        dt.Columns.Add("A");
        dt.Columns.Add("B");
        dt.Columns.Add("C");
        dt.Rows.Add(1, 2, 3);
        this.dataGridView1.DataSource = dt;
        this.dataGridView1.Columns[dataGridView1.Columns.Count - 1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;

      



You may also need to bind the DataGridView to anchor to the right and bottom sides of the form (as well as the left and top) so that the DGV grows in size as the form resizes. (or set the Dock to fill).

+4


source







All Articles