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

Two Control in a Grid Column 5

Status
Not open for further replies.

abbasaif

ISP
Oct 8, 2018
89
AE
Hi,

Can I use two controls in a grid column as shown in image.
Combo and Textbox for different rows.

Please advise.

Thanks

Abbasaif

grdcontrol_iadngt.jpg
 
Do you want the combo box to appear in some rows, and the textbox in others - but in the same column?

If so, add both controls to the same column, then use the column's DynamicCurrentControl property to decide which one you want to display in a given row.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thanks for the reply!

Do you want the combo box to appear in some rows, and the textbox in others - but in the same column?

Yes

If so, add both controls to the same column,
I did it.

then use the column's DynamicCurrentControl property to decide which one you want to display in a given row

How can I do so?

Abbasaif

 

Assume your textbox is named Text1 and your combo is named Combo1. And assume you want the controls to appear in the third column. In the grid's Init, you could do something like this:

Code:
THIS.Column3.DynamicCurrentControl = ;
  "IFF(<some condition>, 'text1', 'combo1')"

where <some condition> represents the condition that will decide which control to show. If the condition is .T. (for a given row), you will see the textbox, otherwsise the combobox.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
A few other points ....

- You will probably need to set the column's Sparse propert to .F. If you don't, you will see the correct control, but only in the currently selected row.

- The <some condition> must refer to a field in the underlying table or cursor.

- Note that I have used double quotes to delimit the string that I am passing to DynamicCurrentControl. This is important because, if you left that out, the IIF() expression would be evaluated straight away (in the Init), and it would be the result of that expression, not the expression itself that was passed to the property. (Of course, you could single quotes or square brackets to delimit the string as well.)

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi,

This syntax is correct?

Code:
THIS.Column4.DynamicCurrentControl = ;
  "IIF('Job.Roll.Sno'='1', 'text1', 'combo1')"

Can I use ICASE instead as I want combo box for 1,2,3, and 10.

Thanks

Abbasaif
 
After putting sparse value = .F. it is showing combo box in all rows.

Thanks

Abbasaif
 
Code:
'Job.Roll.Sno'='1'

You compare two strings here, two strings starting differently. This always results in .F., so you always get the combobox.

The condition has to be something coming from the grid recordsource, Job.Roll.Sno with two dots is not, because neither a workarea alias nor a field name is allowed to contain a dot, so even if you would remove the quotes, this would be a three-part name likely of nothing that exists and erroring. The only chance this changes per row is if the value comes from a field. Something like JobRoll.Sno, for example.

Nobody can tall you what condition you need. But it needs to evaluate to true for the textbox and false for the combobox and it must be something coming from the grid cursor.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Sorry !

This is not
IIF('Job.Roll.Sno'='1'

It is

IIF('JobRoll.Sno'='1'

Thanks

Abbasaif
 
Actually, serial no. is fixed it will not change.
"Sno" is also a field not literals.

Thanks

Abbasaif
 
Abbasaif, the problem is you have too many quotes (as Olaf pointed out). This is what you need:

Code:
THIS.Column4.DynamicCurrentControl = ;
  "IIF(Job.Roll.Sno=1, 'text1', 'combo1')"

(This assumes that Sno is numeric. Is that right?)

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I want the combo box if the following conditions is true:

1. Sno=1
2. sno=2
3. sno=3
4. sno=10

Rest I want the text box.

Thanks

Abbasaif
 
I tried in putting the above code in the init of the grid, but no luck.
"Sno" is a character field.

Thanks

Abbasaif
 
Sno" is also a field not literals.

Yes, it is, as long as you put a name into quotes it is just a string, your expression does not read the field as long as you leave it in quotes. The only quotes you need are the outmost quotes for the whole expression you put into DynamicCurrentControl.

Mike's suggestion should do it, especially if Sno is a numeric field and not a string field.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Thanks, it is done, but why after 10 is also showing combo?

I did like this

THIS.Column4.DynamicCurrentControl = ;
"IIF(INLIST(JobRoll.Sno, '1', '2', '3', '10'), 'Combo1', 'Text1')"

Abbasaif

grd1_fe1et2.jpg
 
Jobroll.Sno, I guess, and otherwise this should work.

For the moment.

Is it always '1', '2', '3', and '10'?

If these numbers are found inside some other table or control, you need to change the condition, for example using SEEK() or LOOKUP() or even calling a function to write out the condition in its most general form the way it's necessary.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top