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!

ForeColor in a textBox in a Container in a grid's column 2

Status
Not open for further replies.

memarques

IS-IT--Management
Aug 28, 2000
22
BR
Hi
I’m trying to create a “MultiLine” grid. So I created a “Container” with a “text Box” in it just to play around, and with “Test Message” as its value, and put this container in one column.

Of course the grid displayed all the rows in the table associated with it, and in this particular column the text “Test Message” is displayed as expected. As I said, just to ply around. My intension is to create a class with name and address (table fields) to display in this column.

My problem is: I don’t know how this text (in the TextBox in the container) adjust they “ForeColor” to display the color defined in “HightLightForeColor” property or the color specified in a command like SetAll("DynamicForeColor",A3,"Column")

The “Text” forecolor always display with the forecolor of its properties. The background color is ok, because I can configure the Container and the textbox as transparent.

Is there any way to make the color of this text display the same color of the rest of the grid?

Regards
Mauro
 
Mauro,

It is possible to achieve the same effect as your [tt]SetAll("DynamicForeColor",A3,"Column")[/tt], but the method is not obvious.

The trick is to use the Backstyle_Access event of the container. This event fires once for each of the rows in the grid. Any code you write in the event will address each row separately.

Despite its name, the event is not necessarily connected with the BackStyle property. For example, you can use it to change the backcolor or the bold or italic setting (which are properties of the column).

As an example, if you want to show the rows in alternating colours, you can use code similar to this:

[tt]this.parent.BackColor = IIF(RECNO() % 2 = 0, RGB(255,128,128), RGB(255, 255, 255))[/tt]

Similarly, you can set any other property of the column (I assume you only have one column). (In the above code, [tt]this.parent[/tt] refers to the column.)

(The above code assumes that the underlying table does not have an index order set or does not contain any deleted records. If that's not the case, refer to thread184-1736373, which discusses workarounds for that situation.)

So, just to be clear: You want to write code in the Backstyle_Access event of the container, but have it address properties of the parent grid's column.

I hope this makes sense.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike

Thanks very much. “With some shame I can say …” Never heard a word about Backstyle_Access event of the container, and after your response I tried to find something about, and found small pieces of information, that I can’t use to “form” a “real” concept.

My problem is not to show the rows in alternating colors, but to preserve the back and fore colors of a container (with some text box) like any other columns with only a textbox.

Can you direct me to some place that I can understand and “feel” correctly the Backstyle_Access concept and how to use it?

Best Regards
Mauro
 
Backstyle_access doesn't exist until you add it as method of your container. It's just the normal way to define the access method automatically triggered when the property named the same way as the first part of the method name. Or to put it the other way around, if you define a new property you are asked, if you want assign and/or access methods for this property. If you check them, vfp creates your property (eg named "yourprop" and also methods "yourprop_assign" and/or "yourprop_access". See the help for more info on these special methods.

You can also define these methods afterwards and you can define them for already existing and native properties. So, if you define a method backstyle_access for your container, it'll be called whenever the grid draws the container of some row. In the end it must return the container.backstyle value, but as Mike indicated, you can do whatever you want in the rest of the code, eg set controls backcolor or whatever else.

Bye, Olaf.
 
Mauro,

To create the Backstyle_Access method, follow these steps:

1. Open your container in the visual class designer.

2. From the Class menu, select Edit Property/Method.

3. Select BackStyle in the list of properties and methods.

3. Tick the box labelled "Access method".

My problem is not to show the rows in alternating colors, but to preserve the back and fore colors of a container

I was only showing you the alternating colours as an example of how to use BackStyle_Access. My point was that you can write any code in that method. The code will then be executed once for each of the rows in the grid.

However, if your poblem is simply to preserve the backcolor and forecolor of the container and/or the textbox, you should make sure that the container's BackStyle property is set correctly. Set it to 0 (Transparent) or 1 (Opaque) according to your needs.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Ok Mike / Olaf

I will take some time to "learn about this", and I'll be back, anyway.

Thank you very much

Have a nice day

Mauro
 
If you require to see multiple line in a single cell (row,col) then you may like to use EditBox.

in the init() of the form
thisform.grid2.rowheight = 40 && Experiment what is the best height for you
thisform.grid2.column3.addobject("EditBox1","EditBox")
thisform.grid2.column3.currentcontrol = "EditBox1"
thisform.grid2.column3.EditBox1.visible = .t.
thisform.grid2.column3.sparse = .f.
thisform.grid2.column3.controlsource = "ADDRESS" && I can not get it working when adding more fields to the same column


try

nasib
 
>thisform.grid2.column3.controlsource = "ADDRESS" && I can not get it working when adding more fields to the same column
What do you expect? An Editbox is not a combobox or listbox allowing many columns. An Editbox just shows text with multiple lines, a single textfield.

No the container as a currentcontrol is fine for displaying any layout of a record, the grid itself then just needs one column with that container, which in turn has all controls you want in whatever layout you want. That's very valid as a solution to overcome the single line rows of grids. But as you use a container you may make the backstyle of the container transparent and all it's controls, too, I doubt you'll see the gridhighlight color or any other automatic coloring by the grid, that's not working this way. If it does, it only takes care of the coloring of the current control, and that would only be the container, not the controls within the container.

That's why the solution is definig the container backstyle_access method, and doing any coloring of any controls in that method yourself.

Bye, Olaf.
 
Nasib said:
If you require to see multiple line in a single cell (row,col) then you may like to use EditBox.

Adding an editbox is quite different from adding a container. With an editbox, you display a single field, with flowing text. With a container, you can display one or more fields, in whataver arrangement you like. For example, you could use it for displaying two or three short pieces of text in the upper row, with a single longer row of text below.

Olaf said:
But as you use a container ... I doubt you'll see the gridhighlight color or any other automatic coloring by the grid

Surprisingly, HighlightStyle does seem to work, even with BackStyle set to transparent. But you can't use the DynamicXX properties.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Ok, way back when I used a container as a vehicle for custom record layouts, there were no HighlightXX-properties. I am not surprised DynamicXX doesn't work, it's not exiting in the grid and just introducing these properties will not induce the behaviour other controls have implemented about the DynamicXX properties.

Bye, Olaf.
 
Mike Lewis said:
The trick is to use the ..._Access event
Great Hint! If I could I would give five stars to you.



Respectfully,
Vilhelm-Ion Praisach
Resita, Romania
 
Any of the column's dynamic properties could be used.
Here is a demo applying this great tip to FontBold (but could be Backcolor, FontItalic, and so on) .
My previous solution was complicated by forcing a value_assign to the textbox of a sparse column. Link

Code:
PUBLIC ofrm
ofrm=CREATEOBJECT("MyForm")
ofrm.show()

DEFINE CLASS MyForm as Form
	showtips=.T.
	ADD OBJECT grd as MyGrid WITH recordsource="cc"
	ADD OBJECT txt as textbox WITH value="", top=210
	cntr=0
	PROCEDURE load 
		CREATE CURSOR cc (ni I AUTOINC,cc char(10) DEFAULT SYS(2015))
		FOR lni=1 TO 15
			APPEND BLANK
		NEXT
		GO TOP 
	ENDPROC
	PROCEDURE Init
		This.grd.setall("DynamicFontBold","ThisForm.grd.FontBold","column")

		BINDEVENT(This.grd.Column2,"MouseMove",This.grd,"MouseMove")
		BINDEVENT(This.grd.Column2.Text1,"MouseMove",This.grd,"MouseMove")
		BINDEVENT(This.grd.Column1,"MouseMove",This.grd,"MouseMove")
		BINDEVENT(This.grd.Column1.Text1,"MouseMove",This.grd,"MouseMove")

		This.grd.nRows=CEILING((This.grd.Height-This.grd.HeaderHeight-1-IIF(INLIST(This.grd.ScrollBars,1,3),18,0))/(This.grd.RowHeight))
		This.grd.anRows[1]=1
		This.grd.anRows[2]=9
	ENDPROC 
ENDDEFINE

DEFINE CLASS MyGrid as Grid
	nRows=0 && number of visible rows in grid
	DIMENSION anRows[2] && anRows[1]=recno of the first row displayed, anRows[2]=recno of the last row displayed
	PROCEDURE FontBold_access
		LOCAL cCur
		cCur=This.RecordSource
		IF This.ActiveRow=0
			DO CASE
			CASE VARTYPE(This.anRows[1])="L"
				This.anRows[1]=RECNO(m.cCur)
			CASE VARTYPE(This.anRows[1])="N"
				IF This.anRows[1]>RECNO(m.cCur)
					This.anRows[1]=RECNO(m.cCur)
					This.anRows[2]=RECNO(m.cCur)+This.nRows-1
				ENDIF
			ENDCASE
			DO CASE
			CASE VARTYPE(This.anRows[2])="L"
				This.anRows[2]=RECNO(m.cCur)
			CASE VARTYPE(This.anRows[2])="N"
				IF This.anRows[2]<RECNO(m.cCur)
					This.anRows[2]=RECNO(m.cCur)
					This.anRows[1]=RECNO(m.cCur)-This.nRows+1
				ENDIF
			ENDCASE
		ELSE
			This.anRows[1]=This.ActiveRow-This.RelativeRow+1
			This.anRows[2]= This.anRows[1]+This.nRows-1
		ENDIF

		RETURN This.FontBold
	ENDPROC
	
	PROCEDURE MouseMove
		LPARAMETERS nButton, nShift, nXCoord, nYCoord
		LOCAL lnRow,MyCursor,lnF1,lnFirst,lnwhere,lni,c1,lcCaption
		cCur=This.RecordSource
		lnRow=FLOOR((nYCoord-OBJTOCLIENT(This,1)-This.HeaderHeight)/This.RowHeight)
		IF This.anRows[2]<RECCOUNT(m.cCur)
			lnF1=This.anRows[1]+m.lnRow
		ELSE
			* Case when the last row is displayed in grid
			lnFirst=OBJTOCLIENT(This,1)+This.HeaderHeight
			lnwhere=-99999
			FOR lni=0 TO This.nRows
				This.GridHitTest(m.nXCoord,m.lnFirst+This.RowHeight*m.lni+1,@lnWhere)
				IF m.lnWhere<>3
					EXIT
				ENDIF
			NEXT
			lnF1=RECCOUNT(cCur)-m.lni+m.lnRow+1
		ENDIF
		* Extracting tooltip
		c1=SYS(2015)
		SELECT cc FROM (m.cCur) WHERE ni=m.lnF1 INTO CURSOR (m.c1)
		lcCaption=&c1..cc
		ThisForm.txt.Value=m.lcCaption
		This.Refresh
		WAIT WINDOW lcCaption NOWAIT 
		USE IN (c1)
		SELECT (m.cCur)
	ENDPROC
ENDDEFINE

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top