load table to datagrid column size

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
Posts: 104
Last visit: Mon Oct 03, 2022 10:50 am
Has voted: 1 time

load table to datagrid column size

Post by Domtar »

Good morning,

I'm building a table with 3 columns, add stuff into it, all good.

Later, I created a datagridview, bound the table to it with

$datagrid.datasource = $table

Looking at the datagridview, I see all the correct data. But the columns are not wide enough to display all the text, only partial text. I am unable to find a property to set the correct size of each column I wish to display.

how can I set the column size to suit my need?

Can someone help?

Posts: 15289
Last visit: Fri Sep 30, 2022 10:38 am
Answers: 26
Has voted: 4 times
Been upvoted: 28 times

Re: load table to datagrid column size

Post by jvierra »

The "Columns" collection has all column objects. Just set the width property as needed or use the autosize property.

Start here: https://www.sapien.com/blog/2020/09/08/ ... w-control/

I also recommend reading the whole article carefully and doing all of the samples and examples.

You should also take some time to review how WinForms and controls work as that will tell you how to find out how to use each control as intended making coding much easier.