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

Some misunderstand in Grid 2

Status
Not open for further replies.

SitesMasstec

Programmer
Sep 26, 2010
523
Brasil
Hello Colleagues!

I have some small aesthetics problems with this Grid:

grid9a_wf3lzu.jpg


1) I am trying to change the color for the Grid Header, but in Grid Properties I don't see something like HeaderBackColor.

2) Also, I would like the contents of columns 1 and 6 to say at the header botton. I change the Properties of the Column1, Alignment to '9-Bottom Center' but the content of Column 1 stays in the above position!

3) And also the position of the contents inside the columns 2 to 9 are not centralized, even they are set '2-Center' in the Text, Alignment properties.


Thank you,
SitesMasstec
 
1. Change colour of column 1's heading:

[tt]THISFORM.Grid1.Column1.Header1.Backcolor = RGB(<whatever>)[/tt]

2. Vertical alignment of headings. You need to do this for the Header, not the column.

[tt]THISFORM.Grid1.Column1.Header1.Alignment= 9[/tt]

3. Alignment of the text in the columns: You need to do this for the column, not the textbox:

[tt]THISFORM.Grid1.Column1.Alignment = 2[/tt]

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I've shown you how to do it for a single column. To apply the same change to all the columns, you could repeat the code for each column in turn. Or you could use the SetAll() method. For example, to change the alignment of all the columns:
[tt]
THISFORM.Grid1.SetAll("Alignment", 2, "Column")
[/tt]
Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
To get BackColor working you also need to turn off Windows Themes rendering, that means use SYS(2700,0). A little warning, that'll turn off many gradient background color renderings and will let the whole screen look different, you might need to adjust more.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Hello colleagues!

Mike, I use all your advices in Form1, Init and none of the 3 commands worked! Or as Olaf warned, I should turn off Windows Themes rendering. But I do not want to change other Windows looks different, for I have users who have Windows XP, 7, 8 & 10 environments, and it would be messing.

That exposed, I understand that all Grid Header will be in gray color (not a good appearance), isn't it?


Thank you,
SitesMasstec
 
You misunderstand. SYS(2700,0) turns off Windows Themes for your application only, it doesn't turn off Windows Themes overall.
If you're in doubt about such a thing, it also helps to refer to the help, once you know SYS(2700) and you can simply try.

Bye, Olaf.

Olaf Doschke Software Engineering
 
I suggest you also look at the Themes property. This is what the Help says about Grid.Themes:

For a Grid control, Themes affects the visual appearance of column headers. If themes are enabled for a grid, the BackColor and ForeColor properties of the header are disregarded because they inherit the attributes of the theme. However, the BackColor and ForeColor properties of a Column object display independently from the setting of a grid's Themes property.

The difference between the Themes property and SYS(2700) is that the former can be applied to a specific control, whereas the SYS() function applies to VFP as a whole.

I usually turn themes off for a grid. I have no problem setting the colours to anything I like.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hello colleagues!

With your valuable help, I am almost there! (the position of the contents inside the columns 2 to 9 are not centralized yet)

Please look at the fields inside the red marked retangle:
grid10a_j9ntiy.jpg


In the Form1 Init I have:
Code:
THISFORM.Grid1.Column1.Text1.Alignment= 1   && Left

THISFORM.Grid1.Column2.Text1.Alignment= 2   && Center
THISFORM.Grid1.Column3.Text1.Alignment= 2
THISFORM.Grid1.Column4.Text1.Alignment= 2
THISFORM.Grid1.Column5.Text1.Alignment= 2
THISFORM.Grid1.Column6.Text1.Alignment= 2
THISFORM.Grid1.Column7.Text1.Alignment= 2
THISFORM.Grid1.Column8.Text1.Alignment= 2
THISFORM.Grid1.Column9.Text1.Alignment= 2

It doesn't obey centralization of columns 2 through 9. An explanation:
The fields TACOENKCQT, TACOCARBQT, TACOPROTQ, etc (from the command bellow) are all Character type, and all have 10 bytes. So the value 363 in column 2, row 1 in fact comes from the table TACOCAR.DBF, which keeps it "363 " (10 characters) in the table. Is this the problem of non centralization in the grid?

Code:
SELECT TACODESCRI, TACOENKCQT, TACOCARBQT, TACOPROTQT, TACOFIBRQT, TACOSODIQT, TACOCOLEQT, TACOCALCQT, TACOFERRQT FROM TACOCAR ;
WHERE UPPER(ParteQualTaco) = UPPER(LEFT(TACOCAR.TACODESCRI,LenParteQualTaco)) ;
INTO CURSOR TEMPTACO
thisform.Grid1.RecordSource = "TEMPTACO"

Thank you,
SitesMasstec
 
Two ideas: While there is the text1 control in a grid column with all the usual properties for databinding (controlsource) and formatting of data (alignment=) all these things should mainly be controlled by thegrid.column. So rather set

Code:
THISFORM.Grid1.Column1.Alignment= 1   && Left

THISFORM.Grid1.Column2.Alignment= 2   && Center
THISFORM.Grid1.Column3.Alignment= 2
THISFORM.Grid1.Column4.Alignment= 2
THISFORM.Grid1.Column5.Alignment= 2
THISFORM.Grid1.Column6.Alignment= 2
THISFORM.Grid1.Column7.Alignment= 2
THISFORM.Grid1.Column8.Alignment= 2
THISFORM.Grid1.Column9.Alignment= 2

Then you're not storing [tt]"363"[/tt] in a char(10) field, you're storing [tt]"363 "[/tt], what you'd actually like to center is the alltrimmed value, you better design the tablel with varchar fields to get that trimming automatic. You could now go for centering the value within the char(10) yourself, but that'll not really make you happy with allignments. Besides numbers arebest aligned right for obvious reasons, but that's of course up to you.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Olaf said:
numbers are best aligned right for obvious reasons, but that's of course up to you.

Yes, I agree with that.

Sites, for your first column, if there are always exactly three digits, you can simply place a couple of spaces before the contents of the field to make it look approximately centred. You can do that in your SELECT:

[tt]SELECT " " + TACODESCRI As TACODESCRI, ....[/tt]

For the columns that have a decimal point, I think you'll find they look better if have the same number of digits after the point, and you right-align them:

[tt]SELECT ..., TRANSFORM(TACOENKCQT, "9999.99") As TACOENKCQT, ...[/tt]

Just my personal opinion.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mission accomplished!!! (with the help od Mike and Olaf)

Now I used Varchar, as Olaf advised me for the contents of the grid to be centralized.
(I am using Varchar for the first time --- and I had wondered before, where I will use this field type.)

grid11_fu9msv.jpg



Thank you,
SitesMasstec
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top