Recent

Author Topic: [SOLVED] StringGrid - Load XML - RowCount Issue  (Read 915 times)

pixelink

  • Hero Member
  • *****
  • Posts: 1260
[SOLVED] StringGrid - Load XML - RowCount Issue
« on: May 27, 2020, 12:09:51 pm »
Hi,
Made an app for myself using StringGrid.
I am saving it using the simple code ...

Code: Pascal  [Select][+][-]
  1. StringGrid1.SaveToFile('myfile.xml');

I am using New, Open, Save, Save As functions on the grid
And I am also using Add/Delete Row.

My issue is that if I have one xml file that has 100 rows and another that has 200 rows.
When I open the file, it doesn't load the file into the grid with the correct amount of rows per xml file.

There is no code in the xml file to specify the row count. I think I need that number to set the "RowCount" of the grid before loading.

Anyone have any ideas and or code on how I can do this easily??
Thanks in advance
« Last Edit: May 27, 2020, 02:23:26 pm by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: StringGrid - Load XML - RowCount Issue
« Reply #1 on: May 27, 2020, 12:37:34 pm »
There's a public property SaveOptions inherited from TCustomGrid in which you can specify what exactly is to be saved:
Code: Pascal  [Select][+][-]
  1. type   // from grids.pas
  2.   TGridSaveOptions = (
  3.     soDesign,             // Save grid structure (col/row count and Options)
  4.     soAttributes,         // Save grid attributes (Font,Brush,TextStyle)
  5.     soContent,            // Save Grid Content (Text in stringgrid)
  6.     soPosition            // Save Grid cursor and selection position
  7.   );
  8.   TSaveOptions = set of TGridSaveOptions;

So, you do this:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   StringGrid1.SaveOptions := [soContent, soDesign];
  4.   StringGrid1.SaveToFile('test.xml');
  5. end;

And you can load the file, with the correct column and row count, in the analogous way:
Code: Pascal  [Select][+][-]
  1.   StringGrid1.SaveOptions := [soContent, soDesign];
  2.   StringGrid1.LoadFromFile('test.xml');
« Last Edit: May 27, 2020, 12:49:38 pm by wp »

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: StringGrid - Load XML - RowCount Issue
« Reply #2 on: May 27, 2020, 01:30:37 pm »
Okay... I will give that a try... THANKS
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: StringGrid - Load XML - RowCount Issue
« Reply #3 on: May 27, 2020, 02:23:10 pm »
Works perfectly.
Thank you WP!!!
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

 

TinyPortal © 2005-2018