PrimalForm: How does the DataGrid work?

This forum can be browsed by the general public. Posting is no longer allowed as the product has been discontinued.
This topic is 14 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
mdomansky
Posts: 3
Last visit: Fri Dec 12, 2008 12:54 am

PrimalForm: How does the DataGrid work?

Post by mdomansky »

I'm familiar with the datagridview in VB.NET but the DataGrid doesn't seem to work the same.I'm not trying to bind it to a datasource, just use it as it for the table functionality.I worked on it for a couple hours and made no progress so I just converted it to a DataGridView.How should it have been done?
User avatar
jhicks
Posts: 1789
Last visit: Mon Oct 19, 2015 9:21 am

PrimalForm: How does the DataGrid work?

Post by jhicks »

This PowerShell script was written before PrimalForms was available, but maybe it will give you an idea of how to use the DataGrid.

Code: Select all

Function Get-ProcessSummary {
$procs=Get-Process | select name,description,starttime,path -errorAction Silentlycontinue

foreach ($process in $procs) {
    if ($process.description -IsNot [string]) {
        $procname=$process.name}
        else {
        $procname=$process.description
        }
    if ($process.starttime -IsNot [DateTime]) {
        $procTime="N/A" }
        else {
        $procTime=($process.starttime).ToString()
        }
    if ($process.path -IsNot [string]) {
        $procPath="N/A" }
        else {
        $procPath=$process.path
        }
        

#create new object to hold values
$obj = New-Object PSObject
Add-Member -inputobject $obj -membertype NoteProperty -Name Name -value $procname
Add-Member -inputobject $obj -membertype NoteProperty -Name StartTime -value $procTime
Add-Member -inputobject $obj -membertype NoteProperty -Name Path -value $procPath

Write-Output $obj

 }
}

[reflection.assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
[reflection.assembly]::LoadWithPartialName("System.Drawing") | Out-Null
 
$form = New-Object System.Windows.Forms.Form
$form.Size = New-Object System.Drawing.Size 800,400
$Form.Text = "Process Summary"

$DataGridView = New-Object System.windows.forms.DataGrid

$array= New-Object System.Collections.ArrayList

$griddata=@(ps | write-output)
$array.AddRange($griddata)
$DataGridView.DataSource = $array
$DataGridView.Dock = "Fill" 

$DataGridView.AllowSorting=$True$form.Controls.Add($DataGridView)
$form.topmost = $True
$form.showdialog() | Out-Null
For other script development questions, I recommend using the PowerShell forum at ScriptingAnswers.com. Use the forums here to report bugs or problems.
User avatar
jpurcell
Posts: 1
Last visit: Thu Apr 23, 2009 10:49 pm

PrimalForm: How does the DataGrid work?

Post by jpurcell »

Thanks for the Snippet Jeff

How would datagrid compare to the gridview (out-gridview) cmdlet in CTP3?

Is it possible to embed that object into a form?

I've been able to sucessfully create some forms using the datagrid, I'd really like to provide similar sort and filter functionality as gridview and while I expect I could write that into my powershell form, I was curiuos about just using the out-gridview cmdlet.

Thanks.



User avatar
jhicks
Posts: 1789
Last visit: Mon Oct 19, 2015 9:21 am

PrimalForm: How does the DataGrid work?

Post by jhicks »

As far as I know the underlying .NET class is the same but clearly with additional features in Out-Gridview. The ability to filter is clearly an advantage. I'm not sure how or even if you could embed it in a WinForm. I tend to think it is unlikely.
This topic is 14 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.