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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rotated label in Grid header

Status
Not open for further replies.

Eliott

Programmer
Nov 8, 2009
91
BA
Greetings Sirs,
I use VFP9 and need a grid with many columns (mostly are single number) but in headers I need custom caption based on rotated label in order to keep columns width equal to 25. I think I saw somewhere how to put textbox into some column but I can't remember I saw that someone had put a label control as title of columns (instead defualt headers). Is it possible?
Some guy said that I need set header height to 0 and then add label, set Rotation property to 90 but I'm unable to do it. I tried something like this one:
Code:
...
.Column1.Width = 25
.Column1.Name = "Column1"
.column1.Header1.Caption = "First columns"
.column1.height = 0
.column1.Header1.addobject("Hlabel1","Label")
with Hlabel1
.Rotation=90
.caption="Signature A"  &&new rotated header (title)
endwith
.Column2.Width = 25
.Column2.Name = "Column2"
...
Thank you.

There is no good nor evil, just decisions and consequences.
 
1. You should set Grid.Headerheight=0, not ColumnX.Height.
2. You could add whatever to an invisible header, it will of course not not bee seen too.

In fact the grid.columnX.header1 objects have no addobject() method, they are not containers, you can't add a label in there.
So add the label outside of the grid and hide the header withgrid.headerheight=0

Bye, Olaf.
 
Thanks Olaf, I thought based on article about multiple label in header I saw years ago in the book about "1001 tricks with VFP" that it's possible to put label into column header and rotate. Shame, it's not possible, I would like it is possible like in Excel I saw... :(
Thanks anyway Olaf. :)

There is no good nor evil, just decisions and consequences.
 
Well, you could set the headerheight high and position a label at the postion in front of the header. The look of a label inside the header button/container is of course possible. Just set the header.caption = "" to have it empty. The bad part about it is, it won't automatically position and move with coluns, especially when setting the columns sizable and or movable.

Bye, Olaf.
 
Eliott,

I don't think you could have seen that in 1001 Things, because that book came out before VFP supported rotation.

What you might be thinking of is the following:

1. Hide the headers completely, by setting Grid.HeaderHeight = 0.

2. Place labels on the form, one for each column. Place them above the grid. Set their captions to what you want the show as the column headers.

3. Set each label's Rotation property to 90.

4. Position each label so that it is just above the column to which it refers.

That should work OK, provided you don't let the user resize or move the grid columns.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
1001 Things was written before we could easily use our own grid column & header classes, too.

I've been thinking for a while that it should be a lot easier to create column & header classes that "know' their label object and fetch it after they've been moved, but I haven't had a reason to fiddle with it. Or maybe not. (Thinking "out loud" here.) Columns and headers still don't have top/left, or any other way to figure location on their parent container. You'd have to go through the columns collection, figuring out .Width and assigning a left coordinate for each column.

It seems like an awful lot of work for something that will, at best, always look beyond normal. [smile]

 
If you absolutely needed this. You could create headers as graphics images in any which way you would like to view and then set the .headerX.picture = title1.bmp

Nasib
 
Dan said:
Columns and headers still don't have top/left, or any other way to figure location on their parent container.

At a pinch, you could do it with the GridHitTest method. But, as you say, Dan, it would be a lot of effort. Better to create a class based on a container, and to use that to hold the grid and the rotated labels. You would still have to disallow the user from resizing or moving the grid columns, but at least the whole thing would be self-contained.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Dear colleagues, thanks you for your valuable inputs. Even hardly I must agree with some of you that wanted grid is "weird" a little in daily VFP application, but I made already huge Excel table with macro support and numerous columns with rotated caption (headers). As I don't have ability to compile Excel table and hide important parts from unconscious users I decided to write from scratch by using VFP9. It's weird for me to have a grid column with width=70px and cell contents is small number (1 or 0 or 5) or single letter just because caption of column is More than one word. Due that I thought that VFP9 is able to show up some "trick" I didn't saw yet. I got idea from article I found on Google book web page 1001 things you wanted to know about VFP, when I thought if it's possible get multiline headers maybe there is space for something other too. Maybe I stated in my earlier post not enough clear, so I wrote this link.
For me, grid object was always a mystery and I used it very carefully if I must to put on my forms, and due that haven't had enough experiences with it. When my try gave me zero as score I turned myself to Tek-tips for help and advice.
Now, I see more far than yesterday, thank you.

There is no good nor evil, just decisions and consequences.
 
Eliott,

I just read the entire chapter on grids from 1001 Things. There is nothing in it about rotated headers.

There is, however, a section on multiline headers. Is that what you were looking at?

I don't think multi-line headers will solve your problem. But the basic principle is the same. Here's what the book says:

1001 Things You Always Wanted to Know ... said:
... the class sets the grid's HeaderHeight property to zero and replaces the header with labels that sit above the grid.

This is exactly the point I (and others) have been trying to make - except that I am proposing that you use the label's Rotation property to rotate the label 90 degrees. I can't see why that shouldn't work.

The code shown in the book is probably more complicated than you need, but the basic principle is sound.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Yes Mike, that's something what I planned to use in my app. Thank you for your kind advice and suggestions.

There is no good nor evil, just decisions and consequences.
 
the class sets the grid's HeaderHeight property to zero and replaces the header with labels that sit above the grid.

Aa Mike pionted out this is what we suggested, but that means the labels are not part of the grid, but seperate, single labels, just positioned above the grid columns. The grid headers themselves are simply collapsed by setting their height to 0.

I like Nasibs idea with graphics, though. You can generate graphics with rotated text by using gdiplus classes, either gdiplusX from VFPX or gdi plus classes included in FoxPros FFC or other samples (don't ask me where to find, but samples section of the task pane should point you to gdiplus. You don't even need to write graphic files, you could set up the headers high and narrow, without any caption and draw rotated text at their position directly on the form.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top