Looking for help with DataGrid

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.
User avatar
jimbobukii
Posts: 52
Joined: Mon Jan 14, 2013 10:34 pm

Looking for help with DataGrid

Post by jimbobukii » Tue Apr 02, 2013 4:38 am

Could anyone point me in the right direction of when I should use DataGrid and how? I have a few lookups which I think could work but need to understand DataGrid

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

Re: Looking for help with DataGrid

Post by jvierra » Tue Apr 02, 2013 6:35 am

Here is a good resource. Scroll forward for datagrid

User avatar
jimbobukii
Posts: 52
Joined: Mon Jan 14, 2013 10:34 pm

Re: Looking for help with DataGrid

Post by jimbobukii » Tue Apr 02, 2013 6:43 am

jvierra wrote:Here is a good resource. Scroll forward for datagrid
I don't understand?

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

Re: Looking for help with DataGrid

Post by jvierra » Tue Apr 02, 2013 8:25 am

Sorry - the link I posted seems to have disappeared.

Try this: http://www.sapien.com/blog/topics/spotl ... -controls/

User avatar
jimbobukii
Posts: 52
Joined: Mon Jan 14, 2013 10:34 pm

Re: Looking for help with DataGrid

Post by jimbobukii » Tue Apr 02, 2013 8:52 am

jvierra wrote:Sorry - the link I posted seems to have disappeared.

Try this: http://www.sapien.com/blog/topics/spotl ... -controls/
I don't seem to see any information regarding GridView
I did check the SpotLights first or am I missing something?

User avatar
davidc
Posts: 5805
Joined: Thu Aug 18, 2011 4:56 am

Re: Looking for help with DataGrid

Post by davidc » Tue Apr 02, 2013 9:02 am

I don't have an article on the DataGridView yet, but it’s on my to-do list.

I recommend referencing the MSDN for help on the control:

DataGridView:

http://msdn.microsoft.com/en-us/library ... dView.aspx

DataGrid:

http://msdn.microsoft.com/en-us/library ... dView.aspx

I also recommend searching the forums, for we have answered variously questions about the control.

David
David
SAPIEN Technologies, Inc.

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

Re: Looking for help with DataGrid

Post by jvierra » Tue Apr 02, 2013 9:13 am

I have a PFF with a demo that I can upload later.

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

Re: Looking for help with DataGrid

Post by jvierra » Tue Apr 02, 2013 9:30 am

Here is a simple demo that loists processes in a DataGrid:
PowerShell Code
Double-click the code block to select all.
$FormEvent_Load={
	#TODO: Initialize Form Controls here
	$arraylist=New-Object System.Collections.ArrayList
     $skuInfo=get-process
     $arraylist.AddRange($skuInfo)
     $datagrid1.DataSource=$arraylist
}
Most PowerShell objects can just be wrapped in an ArrayList and they will display.

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

Re: Looking for help with DataGrid

Post by jvierra » Tue Apr 02, 2013 9:38 am

You can use the exact same technique with the DataGridView control.
PowerShell Code
Double-click the code block to select all.
$FormEvent_Load={
	#TODO: Initialize Form Controls here
	$arraylist=New-Object System.Collections.ArrayList
     $skuInfo=get-process
     $arraylist.AddRange($skuInfo) 
     $datagridview1.DataSource=$arraylist
}

User avatar
jimbobukii
Posts: 52
Joined: Mon Jan 14, 2013 10:34 pm

Re: Looking for help with DataGrid

Post by jimbobukii » Wed Apr 03, 2013 12:26 am

Thanks for the replies I am now making ground. I do however would like to know if this is possible

I am using the following to get my data:
PowerShell Code
Double-click the code block to select all.
$skuInfo= Get-command | Get-subcommand| select one, two, three, four, five, Status | sort -Property four -Descending
so all my columns are generated automaitaclly. I would like to know:
1. How do I get the datagrid to set colum width to the largest data (not a fixed width)
2. How do I get the datagrid to have an auto width rather than a specified one?

Thank you for your help

Locked