I was following along with the guide located here trying to make a GUI with PowerShell, and it all goes well except I have a DataGrid that needs to be populated in my GUI.
In my XML grid I have:
[xml]$form=@"
<Window
[...]
<Grid>
[...]
<DataGrid Name="CSVGrid" HorizontalAlignment="Left" Height="340" Margin="10,60,0,0" VerticalAlignment="Top" Width="765"/>
[...]
</Grid>
</Window>
"@
Now in the tutorial to create the form it uses the following:
$XMLReader = (New-Object System.Xml.XmlNodeReader $Form)
$XMLForm = [Windows.Markup.XamlReader]::Load($XMLReader)
But to get my DataGrid to work, I believe I need to define my "CSVGrid" DataGrid as "system.Windows.Forms.DataGridView" somewhere, but I'm not sure how to tie that together. Running it without defining this will spit out errors if I try to invoke any DataGrid properties, like setting column amounts or column names.
Any ideas?
The way POSHGUI implements their forms actually works perfectly for my purpose, but I prefer editing the WPF forms in Visual Studio. If need be, I can rebuild the form in POSHGUI but hopefully there's a way to tie this together here so I can continue to use the VS GUI for editing the form's GUI.
Edit: It should be noted there's not just the data grid on the form, in case that wasn't clear.
Edit 2: As an extra bit of info, the way POSHGUI formats the controls is like so:
#the form itself
$Form = New-Object system.Windows.Forms.Form
$Form.ClientSize = '400,400'
$Form.text = "Form"
$Form.TopMost = $false
#a datagrid
$DataGridView1 = New-Object system.Windows.Forms.DataGridView
$DataGridView1.width = 382
$DataGridView1.height = 335
$DataGridView1.location = New-Object System.Drawing.Point(8,55)
#a button
$Button1 = New-Object system.Windows.Forms.Button
$Button1.text = "My button"
$Button1.width = 126
$Button1.height = 30
$Button1.location = New-Object System.Drawing.Point(156,13)
$Button1.Font = 'Microsoft Sans Serif,10'
It then ties them together with:
$Form.controls.AddRange(@($DataGridView1,$Button1))
So that happily defines the DataGrid variable as a "system.Windows.Forms.DataGridView", &c, whereas the method of putting the entire XML into a $variable and passing that into a "System.Xml.XmlNodeReader" doesn't make the distinction I don't believe, which is why I'm unable to call any DataGrid properties.
But again, I'd rather create the GUI in Visual Studio if I can...
Edit 3: If it helps at all, checking the intellisense dropdown, various DataGrid properties are there, but not ColumnCount for example:
So maybe it's working as intended? But at the same time, if my DataGrid variable is defined explicitly as a system.Windows.Forms.DataGridView, like in the POSHGUI example, then setting ColumnCount works flawlessly...

