rowfilter doesn't want anymore after saving DGV content to xml

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.
Locked
User avatar
monoeagle
Posts: 107
Joined: Tue Oct 13, 2015 9:10 am

rowfilter doesn't want anymore after saving DGV content to xml

Post by monoeagle » Sun May 01, 2016 3:35 am

Hi@All,

with a little library GUI I have the following problem.

I can add entries, I can remove entries, save and load is also available.

Now I get the problem with filtering.

If I open the gui and try to filter it works.

If I press "speichern" (Save) and try to filter after that it doesn't want.

Any idea?

regards
Attachments
BiBo2.zip
(444.11 KiB) Downloaded 40 times

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

Re: rowfilter doesn't want anymore after saving DGV content to xml

Post by jvierra » Sun May 01, 2016 8:05 am

You are missing pieces:

Directory: C:\ProgramData


Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 5/1/2016 10:59 AM PHS_Library
keine Library gefunden!

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

Re: rowfilter doesn't want anymore after saving DGV content to xml

Post by jvierra » Sun May 01, 2016 10:21 am

It appears to be a bug in the binding between the grid and the table. TO write the XML the table has to alter the default view. After that the grid cannot use it.

Here is a simple workaround.

Code: Select all

#
$table= $datagridviewResults.DataSource.Copy()
$table.WriteXml("$ProgramXMLPath\Library.xml", [system.data.xmlwritemode]::WriteSchema)
Just make a copy of the table and write the copy to the file. This way the view that the grid is using is not altered.

We might also be able to create a custom view for the grid and just reset it. That would require much more code.

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

Re: rowfilter doesn't want anymore after saving DGV content to xml

Post by jvierra » Sun May 01, 2016 11:16 am

The problem also disappears if we switch to using a dataset and a full schema;

This as the load script allows the dataview to work correctly with the grid:

Code: Select all

$MainForm_Load={
$ds=New-Object System.Data.DataSet
if (Test-Path "$global:ProgramXMLPath\Library.xml"){
$ds.ReadXml("$global:ProgramXMLPath\Library.xml")
}else{
Write-Host "keine Library gefunden!"
$ds.ReadXmlSchema('.\Library.xsd')
}
$datagridviewResults.DataSource = $ds.Tables[0]

# it would be best to eliminate this independent variable
$global:table = $ds.Tables[0]
}
I would also avoid creating the global table. Just use the datasource as it will prevent failures as you progress. If you have issues with intellisense then just cast the datasource to a datatable,

As you progress you can add form bindings and have the text and other controls follow the dataset as well as using relations and lookup tables. This can only be done with tables that are part of a dataset.

User avatar
monoeagle
Posts: 107
Joined: Tue Oct 13, 2015 9:10 am

Re: rowfilter doesn't want anymore after saving DGV content to xml

Post by monoeagle » Sun May 01, 2016 2:06 pm

Thanks a lot for the input.

I'll read tomorrow all in detail, 9h on the freeway was more than enough. Time to rest.

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

Re: rowfilter doesn't want anymore after saving DGV content to xml

Post by jvierra » Sun May 01, 2016 2:41 pm

Freeway? What freeway takes 9 hours? Even the LIE seldom takes more than 5.

User avatar
monoeagle
Posts: 107
Joined: Tue Oct 13, 2015 9:10 am

Re: rowfilter doesn't want anymore after saving DGV content to xml

Post by monoeagle » Sun May 01, 2016 11:14 pm

freeway("autobahn") in germany, but the distance was "just" 400km.
The problem was that some others crashed and the autobahn was blocked for several hours and there was no possiblity to get off. ;(

User avatar
monoeagle
Posts: 107
Joined: Tue Oct 13, 2015 9:10 am

Re: rowfilter doesn't want anymore after saving DGV content to xml

Post by monoeagle » Mon May 02, 2016 7:39 am

thx jvierra it works perfectly

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

Re: rowfilter doesn't want anymore after saving DGV content to xml

Post by jvierra » Mon May 02, 2016 9:54 am

Great. I thought the autobahn was always fast like in the song;)

User avatar
monoeagle
Posts: 107
Joined: Tue Oct 13, 2015 9:10 am

Re: rowfilter doesn't want anymore after saving DGV content to xml

Post by monoeagle » Mon May 02, 2016 10:06 am

jvierra wrote:Great. I thought the autobahn was always fast like in the song;)
If all is fine you can get from Dresden to Munich in 2h30 the 460km, but there are a lot of people outside can't handle their car.
The result is a full blockade over 3 lanes and the bigger problem that the rest haven't understood how to build a corridor for emergency vehicle access.

;( ;(

Locked