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.
This topic is 1 year and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
Domtar
Posts: 133
Last visit: Mon Mar 11, 2024 5:38 am
Has voted: 2 times

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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 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.
This topic is 1 year and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked