* * *

Author Topic: Stringgrid InsertRowWithValues: auto add columns?  (Read 4998 times)

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Stringgrid InsertRowWithValues: auto add columns?
« on: October 25, 2014, 04:52:27 pm »
I have an empty stringgrid (no columns, no rows).
I'd like to insert a row with two columns.

I hit on InsertRowWithValues which looks like an easy way to insert data without having to add rows yourself...

When I try this:
Code: [Select]
  MappingGrid.InsertRowWithValues(0,['test1','dest1']);
I get a list index (-1) out of bounds error.

So... perhaps the code does not insert columns? Adding
Code: [Select]
  MappingGrid.ColCount:=2;
does fix the problem.

Would it make sense to submit a feature request for InsertRowWithValues to either
1. add the required columns itself or
2. provide a more meaningful error message (x column values given while the grid only has y columns)?
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1223
Re: Stringgrid InsertRowWithValues: auto add columns?
« Reply #1 on: October 25, 2014, 04:56:57 pm »
My vote is for the second option.

Nice find,  I never knew this existed.
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Stringgrid InsertRowWithValues: auto add columns?
« Reply #2 on: October 25, 2014, 05:22:51 pm »
Mmm, of course, when I tried to write a simple application to reproduce the problem... I didn't get the error.
Didn't get any data either, just apparently empty rows (0 columns? who knows)
Will investigate further when I feel like it :)

Any interested party: test program attached.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Bart

  • Hero Member
  • *****
  • Posts: 3128
    • Bart en Mariska's Webstek
Re: Stringgrid InsertRowWithValues: auto add columns?
« Reply #3 on: October 25, 2014, 05:31:54 pm »
Please submit a bugreport, you can assign it to me.

Bart

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Stringgrid InsertRowWithValues: auto add columns?
« Reply #4 on: October 25, 2014, 07:03:27 pm »
Ok: issue 26943
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Bart

  • Hero Member
  • *****
  • Posts: 3128
    • Bart en Mariska's Webstek
Re: Stringgrid InsertRowWithValues: auto add columns?
« Reply #5 on: October 26, 2014, 04:22:06 pm »
Possible patch attached to bugreport.
Jesus should review it.

Bart

chrnobel

  • Full Member
  • ***
  • Posts: 231
Re: Stringgrid InsertRowWithValues: auto add columns?
« Reply #6 on: November 07, 2018, 05:25:06 pm »
Hi.

I know this is an old topic, but I just had some similar problems with InsertRowWithValues.

The colums were defined, but stil I was not able to insert a row if the rowcount was zero.

I fixed it this way:

if stringgrid1.RowCount=0 then stringgrid1.RowCount:=1;

Bart

  • Hero Member
  • *****
  • Posts: 3128
    • Bart en Mariska's Webstek
Re: Stringgrid InsertRowWithValues: auto add columns?
« Reply #7 on: November 07, 2018, 06:58:38 pm »
This works fine for me (trunk):

Code: Pascal  [Select]
  1. procedure TForm1.Button6Click(Sender: TObject);
  2. begin
  3.   SGrid.RowCount := 0;
  4.   SGrid.InsertRowWithValues(0,['1','2','3'])
  5. end;

Bart

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus