Dynamic rowheight in Foxpro grid

Hi Foxpro Experts,

In my VFP9 application I'm using a data grid with a memo field in a column.
This column contains an editbox component instead of the normal textbox component (and the Sparse property is set to false).

My question is: how can I make the rowheight of the data grid dynamic?  For example, if the memo field contains 1 line, I would like to see a rowheight of 1 line, when the memo field contains 4 lines, I would like to see a row height of 4 lines.  This should be a dynamic height, so each row can have a different height.

Can anyone tell me how I can realize this in VFP9, or is this completely impossible?

Who is Participating?
pcelbaConnect With a Mentor Commented:
This is partially possible. The problem is you cannot have rows of different sizes... But you may change RowHeight property for all grid rows depending on the current record memo field size.

You may implement it in AfterRowColChange event of the grid as it is shown in the code snippet. You should define your own minimum and maximum row size and you may enhance the code by Row change check to avoid useless MEMLINES() calculation if just the column is changed.

*-- AfterRowColChange event:
LOCAL lnHeight
lnHeight = MIN(MAX(25, MEMLINES(YourMemoFieldName) * 18 + 7), 60)
IF THIS.RowHeight <> lnHeight
  THIS.RowHeight = lnHeight

Open in new window

CaptainCyrilConnect With a Mentor Founder, Software Engineer, Data ScientistCommented:
If you are displaying your data, why don't you try to use a WebBrowserControl which can display HTML files and this way you don't need to worry about height. You can also have editboxes on HTML for editing but that will take extra work.
Olaf DoschkeConnect With a Mentor Software DeveloperCommented:
If you take pcelbas Code the grid will be rather bumpy, I wouldn't do it that way. I'd rather display a shortened text, if it has more than can be displayed in a single row. Add an ellipsis (...) at the end of the first line and rather display the full memo value outside of the grid in a seperate Editbox.

Bye, Olaf.
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

JDNAuthor Commented:
Thanks for the comments.
I understand it's impossible in Foxpro to have a dynamic rowheigth, indeed rows of different size.
I've seen this in other applications (created with e.g. Delphi) and I hoped there was a way to achieve this in Foxpro.
Olaf DoschkeSoftware DeveloperCommented:
Well, using another grid (ActiveX) this would be possible, but you wouldn't have the comfort of foxpro's grid's RecordSource. The one you can have, the other you can't. Even if it would be possible, I'd consider my suggestion looking clean and good. It's not that hard to write a function limiting a memo content to the first line. As a start you Select Left(memofield,254) as singleline for the grid column and then you could misuse DisplayPath() to shorten that for display, eg have a controlsource of (DisplayPath(singleline)). And bind memofield to a separate Editbox.

Bye, Olaf.
Olaf DoschkeSoftware DeveloperCommented:
In fact forget DisplayPath as it auto adds CurDir, but take a look at the idea behind it.

Bye, Olaf.
I've requested that this question be deleted for the following reason:

No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Not enough information to confirm an answer.

If you feel this question should be closed differently, post an objection and a moderator will read all objections and then close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

Experts-Exchange Auto Deleter
You may split points among ID: 24469149, ID: 24470146, ID: 24470321
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.