Page 1 of 1

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

Posted: Sun May 01, 2016 3:35 am
by monoeagle
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

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

Posted: Sun May 01, 2016 8:05 am
by jvierra
You are missing pieces:

Directory: C:\ProgramData


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

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

Posted: Sun May 01, 2016 10:21 am
by jvierra
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.
  1. #
  2.         $table= $datagridviewResults.DataSource.Copy()
  3.         $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.

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

Posted: Sun May 01, 2016 11:16 am
by jvierra
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:

  1. $MainForm_Load={
  2.     $ds=New-Object System.Data.DataSet
  3.     if (Test-Path "$global:ProgramXMLPath\Library.xml"){
  4.         $ds.ReadXml("$global:ProgramXMLPath\Library.xml")
  5.     }else{
  6.         Write-Host "keine Library gefunden!"
  7.         $ds.ReadXmlSchema('.\Library.xsd')
  8.     }
  9.     $datagridviewResults.DataSource = $ds.Tables[0]
  10.  
  11.          # it would be best to eliminate this independent variable
  12.     $global:table = $ds.Tables[0]
  13. }
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.

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

Posted: Sun May 01, 2016 2:06 pm
by monoeagle
Thanks a lot for the input.

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

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

Posted: Sun May 01, 2016 2:41 pm
by jvierra
Freeway? What freeway takes 9 hours? Even the LIE seldom takes more than 5.

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

Posted: Sun May 01, 2016 11:14 pm
by monoeagle
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. ;(

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

Posted: Mon May 02, 2016 7:39 am
by monoeagle
thx jvierra it works perfectly

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

Posted: Mon May 02, 2016 9:54 am
by jvierra
Great. I thought the autobahn was always fast like in the song;)

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

Posted: Mon May 02, 2016 10:06 am
by monoeagle
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.

;( ;(