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!

Columns in grid individually readonly

Status
Not open for further replies.

andre65

Programmer
Jan 19, 2003
95
NL
faq184-2324 explains how to make grid columns/cells individually enabled. Works fine!
But ... I want to make them individually ReadOnly, so I can respond to a rightClick event (which won't fires when the TextBox.enabled=.f.)

When testing this situation, I still can modify the contents of the Textbox. Do I something wrong?

Thanks for any reply.

Gr,
André
 
andre65,

If you set the column's ReadOnly to .F., by definition it should make the contents of that column readonly. The only thing I can think of is that your Textbox is not being overridden properly for some reason so you may try and set the readonly property of the contained control (textbox) and have more favorable results.

Slighthaze = NULL
craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
Slighthaze,

When i use the code from FAQ184-2324, remove the click procedure, add property enabled=.f., then the cell will be disabled. When I replace the enabled=.f. property by readonly=.t., the cell will not be readonly. When making the column readonly, the cell is readonly. It seems that making only the cell readonly does not work?

André
 
Andre

Your assessement is correct, although you can have a textbox disabled at the record level (Individual records disabled), this prevents the right-click event of the textbox from firing (This is by default), and changing readonly property of the textbox to .t., will also not work, as the readonly property of the textbox takes on the property of the column (Or the whole grid) which in your case need to be set to False.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Mike,

As I understand, setting ENABLED property of the Textbox does work for the individual cell, setting the READONLY property will not work for the individual cell. Is that not inconsistent?

André.
 
Andre65

As I understand, setting ENABLED property of the Textbox does work for the individual cell

To re-affirm, you CAN have textboxes that are individually disabled (as the FAQ shows you), but disabled means just that = "disabled", including the right-click event. But there are other options that could work for you, for example instead of alternating between a textbox and a disabled textbox, you could alternate between a textbox and a disabled label (which allows the right-click event to fire), or better still, if you use a combimation of controls (like a container with a disabled textbox on it) the container permits the right-click event and you still get the disabled effect. Here is an example in "PSEUDO-CODE" (It will not work if you just run it, but if you implement the technique in design mode you will acheive the desired effect)
Code:
PUBLIC oform1
oform1=NEWOBJECT("form1")
oform1.Show
RETURN
DEFINE CLASS form1 AS form
    DoCreate = .T.
	Caption = "Form1"
	KeyPreview = .T.
	Name = "Form1"
   ADD OBJECT grid1 AS grid WITH ;
		ColumnCount = 2, ;
		Height = 181, ;
		Left = 48, ;
		Panel = 1, ;
		RowHeight = 25, ;
		Top = 36, ;
		Width = 265, ;
		Name = "Grid1", ;
		Column1.Sparse = .F., ;
		Column1.Name = "Column1", ;
		Column2.Name = "Column2"
	ADD OBJECT form1.grid1.column1.header1 AS header WITH ;
		Caption = "Header1", ;
		Name = "Header1"
	ADD OBJECT form1.grid1.column1.text1 AS textbox WITH ;
		BorderStyle = 0, ;
		Margin = 0, ;
		ForeColor = RGB(0,0,0), ;
		BackColor = RGB(255,255,255), ;
		Name = "Text1"
	ADD OBJECT form1.grid1.column1.mycontainer1 AS mycontainer WITH ;
		Top = 23, ;
		Left = 17, ;
		Name = "Mycontainer1", ;
		Text1.Name = "Text1"
	ADD OBJECT form1.grid1.column2.header1 AS header WITH ;
		Caption = "Header1", ;
		Name = "Header1"
	ADD OBJECT form1.grid1.column2.text1 AS textbox WITH ;
		BorderStyle = 0, ;
		Margin = 0, ;
		ForeColor = RGB(0,0,0), ;
		BackColor = RGB(255,255,255), ;
		Name = "Text1"
	ADD OBJECT form1.grid1.column2.text2 AS textbox WITH ;
		Enabled = .F., ;
		Height = 23, ;
		Left = 25, ;
		ReadOnly = .T., ;
		Top = 23, ;
		Width = 100, ;
		Name = "Text2"
	PROCEDURE dinamic
		DO CASE
		CASE myCursor.COLOR = "Blue"
		    RETURN "mycontainer1"
		CASE myCursor.COLOR = "Yellow"
		    RETURN "mycontainer1"
		OTHERWISE 
		    RETURN "Text1"
		ENDCASE
	ENDPROC
	PROCEDURE Load
		CREATE CURSOR myCursor (name c(20),color c(10))
		INSERT INTO myCursor (name,color) VALUES ("Mike","Blue")
		INSERT INTO myCursor (name,color) VALUES ("John","Red")
		INSERT INTO myCursor (name,color) VALUES ("Frank","Yellow")
		INSERT INTO myCursor (name,color) VALUES ("Joe","Black")
		GO TOP
	ENDPROC
	PROCEDURE grid1.Init
		SET STEP ON 
		WITH THIS
		   .column1.DYNAMICCURRENTCONTROL = "thisform.dinamic()"
		ENDWITH
	ENDPROC
	PROCEDURE text2.RightClick
		MESSAGEBOX("hello")
	ENDPROC


	PROCEDURE label1.RightClick
		MESSAGEBOX("Hello")
	ENDPROC


ENDDEFINE
DEFINE CLASS mycontainer AS container
	Width = 87
	Height = 25
	BackColor = RGB(255,255,255)
	Name = "mycontainer"
	ADD OBJECT text1 AS textbox WITH ;
		ControlSource = "mycursor.name", ;
		Enabled = .F., ;
		Height = 23, ;
		Left = -1, ;
		Top = 1, ;
		Width = 86, ;
		DisabledBackColor = RGB(255,255,255), ;
		DisabledForeColor = RGB(0,0,0), ;
		Name = "Text1"
	PROCEDURE RightClick
		MESSAGEBOX("Hello")
	ENDPROC
ENDDEFINE



Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top