Datagridview

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.
Locked
mattys
Posts: 3
Joined: Mon Dec 30, 2019 10:58 am

Datagridview

Post by mattys » Sun Jan 12, 2020 10:21 am

Ive created a datagridview
Im able to import a csv, makes changes, export just fine.
  1. $rows = Import-csv -Path C:\Users\Gino\Documents\receivingTEST.csv
  2.  
  3.     $table = ConvertTo-DataTable -InputObject $rows
  4.  
  5.     Update-DataGridView -DataGridView $datagridview1 -Item $table
Im trying to create preset columns for more functionality, but when I do, the CSV data that is imported is all shifted to the right of Premade columns.
Image
Any help is appreciated.
Attachments
receivingTEST.csv
(177 Bytes) Downloaded 10 times

jvierra
Posts: 14155
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Datagridview

Post by jvierra » Sun Jan 12, 2020 10:37 am

You have to add the columns after you import or pre-create all columns matching the names in the CSV,

mattys
Posts: 3
Joined: Mon Dec 30, 2019 10:58 am

Re: Datagridview

Post by mattys » Sun Jan 12, 2020 11:01 am

Thanks for a fast reply.
Ive tried preseting through the designer with a failed attempt
Image

What am I missing?

jvierra
Posts: 14155
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Datagridview

Post by jvierra » Sun Jan 12, 2020 11:09 am

You have to make the data name the same as the column name. Just changing the display name won't bind the column to the column.

mattys
Posts: 3
Joined: Mon Dec 30, 2019 10:58 am

Re: Datagridview

Post by mattys » Sun Jan 12, 2020 11:14 am

O wow. I completely missed the 'data property name'

Thank you so much jvierra!

jvierra
Posts: 14155
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Datagridview

Post by jvierra » Sun Jan 12, 2020 11:24 am

Yup. I did the same thig the first time I used the DGV.

It is always the best approach to review the online docs for any control you plane to use. It will save you a lot of wasted time.

Locked