Switching datagridview autosizecolumnmode based on form size events

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 7 years and 5 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
robert.ganshorn
Posts: 54
Last visit: Sat Nov 25, 2023 8:17 pm

Switching datagridview autosizecolumnmode based on form size events

Post by robert.ganshorn »

I want a form resize event to determine whether an anchored datagridview should be in 'allcells' or 'fill' column size mode when the form is resized. When the form is sized down, the datagridview is in 'allcellls' column sizing mode so everything doesn't squish. When the form is maximized, it switches to 'fill' so the data uses the entire area of the datagridview.

Hope that makes sense.

Rob
User avatar
robert.ganshorn
Posts: 54
Last visit: Sat Nov 25, 2023 8:17 pm

Re: Switching datagridview autosizecolumnmode based on form size events

Post by robert.ganshorn »

I almost have it using:

$datagridview1.Size.Width
$datagridview1.GetPreferredSize($datagridview1.Size).Width
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Switching datagridview autosizecolumnmode based on form size events

Post by jvierra »

You have to reset the autosizemode property and reload the form.
This topic is 7 years and 5 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