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.
Locked
User avatar
Domtar
Posts: 101
Last visit: Tue Jun 28, 2022 11:00 am

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?

thanks!
jvierra
Posts: 15249
Last visit: Wed Aug 10, 2022 10:37 am
Answers: 23
Has voted: 4 times
Been upvoted: 22 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.
Locked