Hi all,
Unfortunately I’m double posting this item on two websites, sorry for that but I realy need this to work and I’m breaking my head on this matter.
Link to Stackoverflow: http://stackoverflow.com/questions/36254437/powershell-save-edited-datagrid-to-xml-file
Below is my latest code, the link above is for refference.
I’ve created a dataset and this set is showed in the grid. The only thing that still doesn’t work, is save the grid to a variable or directly to the XML file when the button is pressed. And I hope someone could tell or show me how I can get the values of the datagrid back to the dataset and save the set in the XML file. I know that saving the set could be done trough $dt.WriteXML(“xmlfile.xml”)
Link to XML and WPF XAML Pastebin
Script to populate grid with dataset
$dt = New-Object "System.Data.DataTable" "DatacopyGrid" [void]$dt.Columns.Add("Source") [void]$dt.Columns.Add("Destination") ForEach ($Row in $Setting.Setting.Datacopy.Row) { $dt.Rows.Add(@($Row.Source,$Row.Destination)) } $DatacopyGrid.ItemsSource = $dt.DefaultView $DatacopyGrid.CanUserAddRows = $True $DatacopyGrid.CanUserDeleteRows = $True $DatacopyGrid.IsReadOnly = $False $DatacopyBtnStart.Add_Click({ $DatacopyGrid.Rows | select -expand DataBoundItem })
I’ve tried to pull the values from the grid with:
$dt.Items | %{ $_.Subitems[1].Text $_.Subitems[1].Text $_.Subitems[2].Text $_.Subitems[2].Text } $dt.Tables["DatacopyGrid"].Rows[0].Source $dt.Tables["DatacopyGrid"].Rows[0].Destination $dt.Tables["DatacopyGrid"].Rows[1].Source $dt.Tables["DatacopyGrid"].Rows[1].Destination $dt.Tables["DatacopyGrid"].Rows[2].Source $dt.Tables["DatacopyGrid"].Rows[2].Destination
But non of the variables return anything…
Hope to hear and thanks again!
Regards, Paul