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.
This topic is 7 years and 10 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.
Locked
User avatar
monoeagle
Posts: 108
Last visit: Fri Jan 26, 2024 10:44 am

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

Post 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
Attachments
BiBo2.zip
(444.11 KiB) Downloaded 158 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post 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!
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post 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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post 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.
User avatar
monoeagle
Posts: 108
Last visit: Fri Jan 26, 2024 10:44 am

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

Post 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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

Freeway? What freeway takes 9 hours? Even the LIE seldom takes more than 5.
User avatar
monoeagle
Posts: 108
Last visit: Fri Jan 26, 2024 10:44 am

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

Post 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. ;(
User avatar
monoeagle
Posts: 108
Last visit: Fri Jan 26, 2024 10:44 am

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

Post by monoeagle »

thx jvierra it works perfectly
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

Great. I thought the autobahn was always fast like in the song;)
User avatar
monoeagle
Posts: 108
Last visit: Fri Jan 26, 2024 10:44 am

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

Post 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.

;( ;(
This topic is 7 years and 10 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.
Locked