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

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

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.
4,607 questions
No comments
{count} votes

Accepted answer
  1. answered 2022-06-28T18:16:29.593+00:00
    Rich Matheisen 34,791 Reputation points

    Try using System.Windows.Forms.DataGridView instead of System.Windows.Forms.DataGrid.

    No comments

2 additional answers

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

    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()

    No comments

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

    wow, that was easy.

    thanks!

    No comments