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!

How to set DisplayValue when RowSourceType = 1 2

Status
Not open for further replies.

Rajesh Karunakaran

Programmer
Sep 29, 2016
549
MU
Hi,

I have a combo in a grid where the RowSourceType = 1 and RowSource is 'First,1,Second,2,Third,3,Fourth,4'.
I have BountTo = .t. and BoundColumn = 2. The RecordSource is a cursor.

Suppose, in the first row, I have selected 'First' and then the 'Value' of combo is 1.
Now, when the focus is not in that column of the grid with this combo, I want the column to display First, not 1.
I am not able to figure out what should I set the 'DisplayValue' to!

Thanks in advance.
Rajesh
 
Hi Rajesh,

I'm sorry but I don't fully understand what you'd like to achieve, but maybe the example below is able to give some hints

Code:
PUBLIC goForm1

goForm1=NEWOBJECT("form1")
goForm1.Show

READ EVENTS

CLEAR ALL

RETURN

DEFINE CLASS cboDebitCredit as ComboBox 
	RowSourceType = 1
	RowSource = "One,1,Two,2,Three,3,Four,4"
	ControlSource = "curBanks.cBalance"
	ColumnCount = 2
	ColumnWidths = "60,0"
	IncrementalSearch = .T.
	Style = 2
	
	PROCEDURE InterActiveChange()
		Replace curBanks.iBalance WITH VAL(This.List[This.ListIndex, 2])

		WITH ThisForm
			.Refresh()
		ENDWITH 
			
	ENDPROC
ENDDEFINE 

DEFINE CLASS form1 AS form
	Height = 240
	Width = 360
	Autocenter = .T.
	Borderstyle = 2

	ADD OBJECT grdBanks AS Grid WITH ;
		DeleteMark = .F., ;
		Left = 12, ;
		Top = 12, ;
		Width = ThisForm.Width - 24, ;
		Height = ThisForm.Height - 24, ;
		RowHeight = 24, ;
		ColumnCount = 2, ;
		Visible = .T.

		PROCEDURE grdBanks.Init()		
			WITH This.Column1
				.Header1.Caption = "Text"
				.Width = 90
				.RemoveObject("Text1")
				.AddObject("cboDC","cboDebitCredit")
				.CurrentControl = "cboDC"
				.cboDC.Enabled = .T.
				.cboDC.Visible = .T.
				.Sparse = .F.

			ENDWITH
			
			WITH This.Column2
				.Header1.Caption = "Value"

			ENDWITH 
	
	PROCEDURE Load
		CREATE CURSOR curBanks (cBalance C(10), iBalance I)
			INSERT INTO curBanks VALUES ("One", 1)
			INSERT INTO curBanks VALUES ("Two", 2)
			INSERT INTO curBanks VALUES ("Three", 3)
			INSERT INTO curBanks VALUES ("Four", 4)
			
			LOCATE 

	ENDPROC 

	PROCEDURE Destroy()
		CLOSE ALL 
		CLEAR EVENTS 
	
	ENDPROC 		
ENDDEFINE

hth

MarK
 
Dear Olaf, I think I couldn't make my query clear to you!
Dear Mark, Thank you very much for that complete code.

In fact, I was creating all combos through code, not at design time! However, I am not sure why I was not getting it right earlier. Now, when I completely rewrote the code for that combo with fixed values (RowSourceType = 1), I am getting the name as display value and code as value. It works the way I wanted without doing anything specifically for it. That would mean I had a miss earlier, I am not sure what it was though!

Thank you so much for your suggestions!
Rajesh
 
Any control always displays sparse, only in the active row, unless you set sparse=.f. and any combo, no matter what rowsourcetype. always display the first column as the display text after a selection was made.

So you typically use a rowsourcetype of fields and set the thing to display as fiorst column, an ID - typically what you want to store into the controlsource is put into the second column and you set boundcolumn=2.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top