Hi..
How to automatically Set height of datagridview based on number of rows in windows Forms using vb.net
DataGridView
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Hemant SrivastavaRank #581 · 4.2K reputationPosted Nov 14, 2012, 11:05 AM EST
Suppose you are binding a list/DataTable (or any IEnumerable object) into your dataGridView
For example you have data table "dt", firstly get its Rows count
then calculate height of DataGridView dynamically:
int height = dt.Rows.Count * dataGrid.RowTemplate.Height; Then adjust the height Size size = new System.Drawing.Size(250, height); dataGrid_ZipList.Size = size; //Bind your datatable into grid dataGrid_ZipList.DataSource = dt; In this way , you could adjust height of datagrid dynamicallyHemant SrivastavaRank #581 · 4.2K reputationPosted Nov 14, 2012, 11:06 AM EST
Thanks,
Hemant