Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2014-09

Selection issues in class derived from TCustomDrawGrid

5 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Werner Pamler

In fpspreadsheet I am using a TsWorksheetGrid to display the contents of spreadsheet files. This grid is derived from TCustomDrawGrid, it gets all data and formats from the underlying TsWorkbook.

One thing which annoys me is that the grid can no longer select a range of cells once the goEditing option is set. An ordinary TDrawGrid has the same issue, but a TStringGrid on the other hand works perfectly. Therefore I guess that I forgot to modify a property. I looked for some time but cannot find the clue.

Any idea?

Reply by email

Rik van Kekem
to Werner Pamler
Werner Pamler wrote 7 lines
In fpspreadsheet I am using a TsWorksheetGrid to display the contents of spreadsheet files. This grid is derived from TCustomDrawGrid, it gets all data and formats from the underlying TsWorkbook. One thing which annoys me is that the grid can no longer select a range of cells once the goEditing option is set. An ordinary TDrawGrid has the same issue, but a TStringGrid on the other hand works perfectly.

Is this in the latest svn-version (3561)? I'm not seeing this issue.

I've never used the gui-components and see some other weird stuff (like reading an .ods gives me an error about adding a empty name for a worksheet and when changing a cell in the grid i get an invalid date format error but that's probably something i'm doing wrong :).

For the TsWorksheetGrid, i can just drop it on a form, set goEditing in Options, do a sWorksheetGrid1.LoadFromSpreadsheetFile and select multiple cells. (You're right that that doesn't work in TDrawGrid but for TsWorksheetGrid it works for me)

Could you provide sample code? (or is it also just as simple as mine?)

(or am i not understanding the problem correctly?) See: http://i.imgur.com/ikwdhb6.png

(Lazarus 1.3 r46216M FPC 2.7.1 i386-win32-win32/win64) (fpspreadsheet svn 3561)

Reply by email

Werner Pamler
>> Is this in the latest svn-version (3561)?

Yes, but I've seen it for a couple of months since I added selections to the worksheet grid.

>> Could you provide sample code? (or is it also just as simple as mine?)

Yes, just like what you say. Or just run "spready" which starts with an empty spreadsheet, activate editing (by clicking at the pen icon in the toolbar), click at any cell, hold shift down and click at any other cell. You should see the selected cells with modified background color and enclosed by a thick selection rectangle. It does not work for me. If you disable editing (by clicking on the pen icon another time) and repeat the same, everything works as expected.

>> some other weird stuff (like reading an .ods gives me an error

about adding a empty name for a worksheet and when changing a cell in the grid i get an invalid date format error
To keep things apart could you write a bug report? Add a short demo and give step-by-step instructions for me to follow what you are doing. I don't understand this short desciption here because you are saying that you change a cell in the "grid", but you also say that you never used the gui-components - the grid is one...

Just these two comments:
- Invalid sheet names have been addressed in a recent commit (a few days ago). Sheet names must follow the rules set up for Excel (which seem to be valid for ods as well).
- A date format error does happen with TsWorksheetGrid after entering data because here strings are entered in the first place. The grid tries to determine from the string which type of cell has to be used in the worksheet. Unfortunately, the TryStrToDateTime() function does raise an exception - this is different from TryStrToFloat for ordinary numbers (and also different from Delphi)... I plan to take the time to rearrange the code in StrToDateTime and TryStrToDateTime such that the latter one just returns true or false, without an exception. Anyway, this error does not occur when the program runs outside of Lazarus.

Reply by email

Rik van Kekem
to Werner Pamler
Werner Pamler wrote
Or just run "spready" which starts with an empty spreadsheet, activate editing... It does not work for me.

When setting ExtendedSelect to true for the WorksheetGrid it works like expected (that's why it worked for me with a clean project because it's default true in a TsWorksheetGrid but for some reason you set it to False in the spready demo).

>>> some other weird stuff (like reading an .ods gives me an error about adding a empty name for a worksheet and when changing a cell in the grid i get an invalid date format error

I've never used the gui-components and reading of .xls/.ods but just for this occasion i tried it with a simple demo (to see what went wrong).

I see the exception with invalid date is indeed only in the IDE. The <"" is not a valid worksheet name.> i still get with loading a simple .ods. (just a simple .ods, .xlsx works fine, with some fields filled and default sheet-names also gives this error in the spready demo)

But if you don't get this with an .ods i'll try to figure out why it's only for me. (and if i find out i'll open a bugreport)

Reply by email

Werner Pamler
>> When setting ExtendedSelect to true for the WorksheetGrid it works like expected

Yes, you are right - thanks. In fact, in my current version I already had the ExtendedSelect set to TRUE in the constructor but I had forgotten to update its default value in the property declaration as well. After doing this and deleting the FALSE from the lfm file it works now as expected.

I also fixed the ods bug with the empty sheet name - it was there all the time, but only detected after checking the sheet names...

Reply by email