how to resize columns after loading a table into a datagrid view

Daniel Brassard 21 Reputation points
2022-06-28T17:23:30.527+00:00

hi all,

I'm loading a datatable with stuff that I display in a datagridview in my GUI.

The table has the correct information, the Datagridview displays it, but the issue is that the columns do not resize themselves to show all of the text, I have only partial values.

How can I change the size of the column programmatically? I do not see any property to allow me that.

thanks!

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,407 questions
0 comments No comments
{count} votes

2 additional answers

Sort by: Most helpful
  1. Daniel Brassard 21 Reputation points
    2022-06-28T18:00:32.83+00:00

    the property AutoSizeColumnsMode exists when I use the GUI tool to create my GUI.

    It does not exists if I create it programmatically.

    $form = New-Object system.Windows.Forms.Form
    blabla
    $data = New-Object System.Windows.Forms.DataGrid
    blabla

    $form.Show()

    0 comments No comments

  2. Daniel Brassard 21 Reputation points
    2022-06-28T18:17:37.71+00:00

    wow, that was easy.

    thanks!

    0 comments No comments