×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

How to set DisplayValue when RowSourceType = 1
2

How to set DisplayValue when RowSourceType = 1

How to set DisplayValue when RowSourceType = 1

(OP)
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

RE: How to set DisplayValue when RowSourceType = 1

You set the columns sparse=.f. to also have a ComboBox when the cell doesn't have focus.

Bye, Olaf.

Olaf Doschke Software Engineering
https://www.doschke.name

RE: How to set DisplayValue when RowSourceType = 1

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

RE: How to set DisplayValue when RowSourceType = 1

(OP)
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

RE: How to set DisplayValue when RowSourceType = 1

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
https://www.doschke.name

RE: How to set DisplayValue when RowSourceType = 1

...it also doesn't matter, whether you add the combo with code or at design time already.

Bye, Olaf.

Olaf Doschke Software Engineering
https://www.doschke.name

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close