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,628 questions
0 comments No comments
{count} votes

Accepted answer
  1. Rich Matheisen 47,786 Reputation points
    2022-06-28T18:16:29.593+00:00

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

    0 comments No comments

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

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.