1 (edited by AD1408 2017-12-28 11:00:29)

Topic: Operators, tGrid and a Label

I'm using label to display a value from tGrid

Form1.label4.Caption := Form1.TableGrid1.Cells[0,Form1.TableGrid1.SelectedRow];

It works OK, if tGrid has a record.
If tGrid is empty, doesn't contain any record (row) then it produces "List index out of bounds (-1)" error.
onShow event.


In order to eliminate the error I tried

if form1.TableGrid1.dbItemID < 0 then Form1.label4.Visible := False else Form1.label4.Visible := True;

Tried it with dbItemID, RowCount and SelectedRow without a success?


------------------------------------------------------


On label front;
When a value doesn't fit the allocated label length, how can I get it displayed ending bit with 3 dots.
i.e.
This is a long name that doesn't fit
if I turn auto size to false it displays
This is a long name t
I like to display it as:
This is a long nam...


Happy New Year to All...................................

Adam
God... please help me become the person my dog thinks I am.

2 (edited by derek 2017-12-28 14:40:55)

Re: Operators, tGrid and a Label

Hi Adam,
Attached is a couple of ways to do it (one of which traps for the 'list index....' error and the other (the simplest) by which it can never happen anyway).
Also is a suggestion for the '...' for when a field is too long (there may be other and better ways of doing it - but as you know, I like to keep things simple!).  You could also combine the '...' with passing the contents of the field that is too long for the label into a 'hint (I've put it in the script just to show how it could work).
Regards,
Derek.

Post's attachments

Attachment icon adamlabel.zip 338.62 kb, 415 downloads since 2017-12-28 

Re: Operators, tGrid and a Label

Hi Derek,


Thank you very much for the error elimination and for label length solution with alternatives .........................
Truly appreciated...........................


I like the approach of going to source (DB Table) rather than getting it from tGrid cell. This would also prevent need of script update when columns order on related tGrid changed.


On text display length, including hint has been additional bonus for me. One thing, when applying hint, we need to make sure item properties ShowHint checked.

Adam
God... please help me become the person my dog thinks I am.