Support Forums

Can't get datagrid to export to CSV

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.
User avatar
WEAVER84
Posts: 9
Joined: Wed Feb 10, 2016 2:50 pm

Can't get datagrid to export to CSV

Postby WEAVER84 » Wed Feb 10, 2016 2:58 pm

Hello,

So I can get the datagrid to display everything I want and how I want, but just can't seem to get it to export the information. It will save a CSV in the location I tell it to, just won't display the data from the datagrid into the CSV... Attached is my PSF file. I'm really new at using Powershell Studio so assuming I'm probably missing something simple.

Let me know if anyone has any questions regarding this. (I'm pretty new powershell as well... :oops: )

Thanks
Attachments
IAM1.psf
(35.89 KiB) Downloaded 101 times
User avatar
jvierra
Posts: 9738
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Can't get datagrid to export to CSV

Postby jvierra » Wed Feb 10, 2016 3:09 pm

Hi weaver. It takes one line:

$datagridview1.Rows | select -expand DataBoundItem | Export-Csv $savexml -NoType
User avatar
WEAVER84
Posts: 9
Joined: Wed Feb 10, 2016 2:50 pm

Re: Can't get datagrid to export to CSV

Postby WEAVER84 » Wed Feb 10, 2016 3:18 pm

When I use that it just gives me a blank CSV file unfortunately
User avatar
jvierra
Posts: 9738
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Can't get datagrid to export to CSV

Postby jvierra » Wed Feb 10, 2016 3:20 pm

How are you loading the grid?
User avatar
jvierra
Posts: 9738
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Can't get datagrid to export to CSV

Postby jvierra » Wed Feb 10, 2016 3:22 pm

Try this:
Attachments
Demo-DGVExport.psf
(13.84 KiB) Downloaded 112 times
User avatar
WEAVER84
Posts: 9
Joined: Wed Feb 10, 2016 2:50 pm

Re: Can't get datagrid to export to CSV

Postby WEAVER84 » Wed Feb 10, 2016 3:41 pm

I'm going to have to play around more this tomorrow. Can't seem to get it working with that information.

But in your example, when the form loads I should load a file? I'm wanting to create a new file though. Didn't understand that part.

I'll let you know what I come across tomorrow morning when I have some more time. Thanks for the help!
User avatar
WEAVER84
Posts: 9
Joined: Wed Feb 10, 2016 2:50 pm

Re: Can't get datagrid to export to CSV

Postby WEAVER84 » Wed Feb 10, 2016 7:05 pm

jvierra wrote:How are you loading the grid?


$datagridview.rows.add("randomstuff", "morerandomstuff")
User avatar
jvierra
Posts: 9738
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Can't get datagrid to export to CSV

Postby jvierra » Wed Feb 10, 2016 7:27 pm

You need to use objects and you need to update the data in the underlying dataset. Editing the grid does not stick until you accept the changes.
User avatar
WEAVER84
Posts: 9
Joined: Wed Feb 10, 2016 2:50 pm

Re: Can't get datagrid to export to CSV

Postby WEAVER84 » Thu Feb 11, 2016 7:18 am

I was thinking it wasn't saving somewhere that's why it wasn't working... Is there an easy example of how that is supposed to be done somewhere? Otherwise I can always search around google to see what I can find.


Thanks
User avatar
jvierra
Posts: 9738
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Can't get datagrid to export to CSV

Postby jvierra » Thu Feb 11, 2016 8:03 am

I attached a sample above al long to me ago.

Return to “PowerShell GUIs”

Who is online

Users browsing this forum: No registered users and 3 guests