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

explicit value in grid's textbox

Status
Not open for further replies.

bon011

Programmer
Jun 2, 2002
155
CZ
Hi all,

I've got an interesting problem.
I have grid with 2 columns. In the first column I wont to show name and in the second column I wont to show explicit value.
Description:
Table(Name C(20), state N(1))

Field mode can have value 1,2 or 3.
Value 1 means -single
Value 2 means -married
Valeu 3 means -divorced



Grid should look like this:
----------------------
|Name | State |
|---------------------|
|John | single |
|Jimmy | married |
|Kate | divorced|
-----------------------

Table looks like this:
----------------------
|Name | State |
|---------------------|
|John | 1 |
|Jimmy | 2 |
|Kate | 3 |
-----------------------

How to display that in grid???????

Thanks
 
bon011

Use the .DynamicCurrentControl property of the column to call a form method, set .Sparse = .F. for the column, and don't set a ControlSource for the textbox in the column

In the method put :-

DO CASE
CASE TABLENAME.state = 1
[tab]THISFORM.grid1.Column2.Text1.Value = [Single]
CASE TABLENAME.state = 2
[tab]THISFORM.grid1.Column2.Text1.Value = [Married]
CASE TABLENAME.state = 3
[tab]THISFORM.grid1.Column2.Text1.Value = [Divorced]
ENDC


FAQ184-2483 - the answer to getting answered.​
Chris [pc2]
 
Beside Chris' suggestion using dynamiccurrentcontrol, another way of using it would be to "switch" between 3 different labels. Copy the following in a program and run it to see how its done.
Code:
Create Cursor myCursor (Name c(20),state N(1))
Insert Into myCursor (Name,state) Values ("John",1)
Insert Into myCursor (Name,state) Values ("Jimmy",2)
Insert Into myCursor (Name,state) Values ("Kate",3)
Go Top
oForm = Createobject("form")
oForm.AddObject("grid1","grid1")
oForm.grid1.column2.AddObject("label1","label1")
oForm.grid1.column2.AddObject("label2","label2")
oForm.grid1.column2.AddObject("label3","label3")
oForm.grid1.column2.sparse=.f.
oForm.Show(1)

Define Class grid1 As Grid
	Procedure Init
	This.column2.DynamicCurrentControl = "dynamic()"
	endproc
	ColumnCount = 2
	Visible = .T.
Enddefine
Define Class label1 As Label
	Visible = .T.
	Caption = "single"
Enddefine
Define Class label2 As Label
	Visible = .T.
	Caption = "married"
Enddefine
Define Class label3 As Label
	Visible = .T.
	Caption = "divorced"
Enddefine
Procedure Dynamic
Local lcReturn
Do Case
Case myCursor.state = 1
	lcReturn = "label1"
Case myCursor.state = 2
	lcReturn = "label2"
Case myCursor.state = 3
	lcReturn = "label3"
ENDCASE
     RETURN lcReturn
Endproc


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