Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable row height in grid

Status
Not open for further replies.

roger9991

Programmer
Apr 18, 2009
23
US
I need to vary the row height in a grid to accomodate the contents of a memo field which will vary from one line to 6. Each row in the grid would have different memo fields of different lengths.
 
Rowheight is fixed to the grid and applies to all rows. Make it large enough to accomodate all of the largest memo fields and tolerate the empty space, or...

You could put an edit control in that column with scrollbars enabled so the user could scroll through the contents of the memo field, or give the control in that column a click method that opens the memo field in another place.
 
Dan's right. The grid as a whole has a RowHeight property. You can't change it for individual rows. I suggest you display, say, the first two lines of the memo in each row, and let the user double-click in the cell to open a form that displays the full memo.

If you desperately want to display the entire memo in a variable-height row, an alternative would be to use a third-party grid control. For example, the Report Control from Codejock Software ( provides that facility (it can also display text that extends over the width of several cells), but it's vastly more difficult to use than a VFP grid.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
I sometimes use a double click arrangement to increase the row height for the selected record... you double click on it and the row height goes to 200, double click again and it reduces to 20 or so.

Watch our for one little VFP niggle. Make sure you use an edit box in the grid for any memo field - if a text field exceeds about 220 characters the grid may become unstable, and if it exceeds 254 it will almost definately crash.

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
I sometimes use a double click arrangement to increase the row height for the selected record... you double click on it and the row height goes to 200, double click again and it reduces to 20 or so.

Martin, do you mean that the double-click increases the row-height for the entire grid? Or have you found some way of doing it for the selected row?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Hi Mike,

I mean the entire Grid - I increase the row height to almost the height of the grid... thereby making it LOOK like
it is just the row.

You can do this with a gotfocus/lostfocus approach too - but I like it to be more deliberate.

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
Roger,

Did you read the replies to your question? You received several responses, and it would be useful to know if they were helpful - if only for the benefit of other people who might have the same problem. (It's also a courtesy to acknowledge the replies you received.)

Regarding your last post, you say that the page Mike Gagnon suggested is in French. In fact, the code will run correctly regardless of the language. As far as I can see, there is only one comment in French, and that simply says that the code shows how to make Flexgrid editable, the second column being the editable one.

You also asked how to download the VCX? It's not a VCX, it's an ActiveX control, and it is already on your computer.

Add a OLE Container control to your form, and when you see the Insert Object dialogue, select "Microsoft Flexgrid Control version 6.0 (SP2)".

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Add a OLE Container control to your form, and when you see the Insert Object dialogue, select "Microsoft Flexgrid Control version 6.0 (SP2)"

Actually, you don't even need to do that. Just copy and paste the code into a PRG and run it. It works.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Roger,
Mike is correct the code will work. However to see the entire page in your language you may want to use the Google translator:
1. store the url on your clipboard
2. start Google
3. in the search box you copy the clipboard = url content
4. first given found is the webpage now instead of clicking on the title you click on the button translate next to the title.
5. select your language however preferable english and almost everything on the page is translated to your language.
This trick even enables you to read the russian vfp usergroup.

Regards,

Jockey(2)
 
Thank you for all your help. I added an OLE Container control to form and selected "Microsoft Flexgrid Control version 6.0 (SP2)".
However, I cannot figure out how this control works. I looked in properties and there is a "rowheightmin" which is set to 0 by default. Where in the properties is the parameter to adjust the height for each row? I want to thank everyone for their help.
 
roger9991

There is an inner MHT page in the link I gave you, with different examples. The varying row height sample shows this code (in the init of the control)
Code:
Local lngWidth, i, x

lngWidth  = 2200 && Twips

Select moncurseur

Count To x

With This

      .Cols = 2  && Nombre de colonnes incluant la première.

      .Rows = 0

      .AddItem(Chr(9)+"Nom du client")  && Entetes

      .Rows = x+1  && Nombre de rangées

      .FixedRows = 1

      .WordWrap = .T.

      .RowHeight(0) = .RowHeight(0)*2

      .RowHeight(1) = .RowHeight(1)

      .RowHeight(2) = .RowHeight(2)*4.5

      .RowHeight(3) = .RowHeight(3)*2

      .RowHeight(4) = .RowHeight(4)*.8

      .RowHeight(5) = .RowHeight(5)*3.5

      .ColWidth(0) = 0  && Ajuster la largeur des colonnes

      .ColWidth(1) = lngWidth*1.5

      Select moncurseur

      i = 1

      Scan

            .TextMatrix(i, 1) = moncurseur.Name

            i = i + 1

            If i > x

                  Exit

            Endif

      ENDSCAN

Endwith


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
ReFox XI (www.mcrgsoftware.com)
 
Roger,

Where in the properties is the parameter to adjust the height for each row?

Essentially, you set the Rows property to the number of rows you want. You can then access an array of RowHeight properties, one for each row. So .RowHeight(2) would be the height of the third row, and so on. (Caution: The array is zero-based.)

Before you rush into this, be aware that the Flexgrid is quite different from the native VFP grid. It has pros and cons. It will certainly give you what you want, which is to vary the height of an individual row, but there might be other issues that you need to take into account.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
What does .TextMatrix(i, 1) = moncurseur.Name represent?
I actually mean "moncurseur.Name"
Thank you for your help.

 
Moncurseur" is just an example of the name of a cursor. In Mike's sample code, it's the cursor that's used to populate the grid.

The example assumes the cursor has a field named Name. So Moncurseur.Name is the Name field in the Moncurseur cursor.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
The grid works but it does not adjust the height of the rows to accomodate the amount of data in the memo field. Fopr example, the row height is very small and the amount of text in the field is too large. IN other cases, there is simply one line of text and the row height is high. Is there a way to adjust row height for text of memo field? Thank you for your help.
 
Is there a way to adjust row height for text of memo field?

First, determine the number of lines of text you need. You can do that with MEMLINES() and SET MEMOWIDTH. You'll need to know the width of a line in characters. You might have to estimate that, since the width of the cell is defined in pixels.

Next, you use TEXTHEIGHT() to get the total height of the text. This will be in pixels, which is what you want.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top