×
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!
  • Students Click Here

*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

Two Control in a Grid Column
4

Two Control in a Grid Column

Two Control in a Grid Column

(OP)
Hi,

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

Please advise.

Thanks

Abbasaif

RE: Two Control in a Grid Column

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

RE: Two Control in a Grid Column

(OP)
Thanks for the reply!

Quote:

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

Yes

Quote:

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

Quote:

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

RE: Two Control in a Grid Column


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

RE: Two Control in a Grid Column

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

RE: Two Control in a Grid Column

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

RE: Two Control in a Grid Column

(OP)
After putting sparse value = .F. it is showing combo box in all rows.

Thanks

Abbasaif

RE: Two Control in a Grid Column

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

RE: Two Control in a Grid Column

(OP)
Sorry !

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

It is

IIF('JobRoll.Sno'='1'

Thanks

Abbasaif

RE: Two Control in a Grid Column

Then you still compare two string literals, not the field.

Bye, Olaf.

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

RE: Two Control in a Grid Column

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

Thanks

Abbasaif

RE: Two Control in a Grid Column

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

RE: Two Control in a Grid Column

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

RE: Two Control in a Grid Column

So you want

CODE -->

THIS.Column4.DynamicCurrentControl = ;
  "IIF(INLIST(Job.Roll.Sno, 1, 2, 3, 10), 'combo1', 'text1')" 


Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Two Control in a Grid Column

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

Thanks

Abbasaif

RE: Two Control in a Grid Column

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

RE: Two Control in a Grid Column

>"Sno" is a character field.

Then you need to put the numbers in quotes, but only the numbers, not the field name.

Bye, Olaf.

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

RE: Two Control in a Grid Column

So you need this:

CODE -->

THIS.Column4.DynamicCurrentControl = ;
  "IIF(INLIST(Job.Roll.Sno, '1', '2', '3', '10'), 'combo1', 'text1')" 

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Two Control in a Grid Column

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

RE: Two Control in a Grid Column

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

RE: Two Control in a Grid Column

Do this in the command line:

CODE -->

? '11'='1' 

Learn about how VFP compares strings.

Bye, Olaf.

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

RE: Two Control in a Grid Column

(OP)

Quote:

For the moment.

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

Yes,

All the format is fixed, except the last column "Acceptance". There would be no changes in Sr.No. (Sno).

I think, it is because of '1' which contain in 10,11,12,13, 14 and 15.

Abbasaif

RE: Two Control in a Grid Column

What is your setting for SET EXACT? (Although I'm not sure if it would make a difference in this case.)

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Two Control in a Grid Column

This will do:

CODE

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

If Sno is C(2), then you can and need to use '10', but overall if your Sno actually is a string that actually is a number, I assume it will be C(11) at least to have a larger range than integers. It's useless most of the time, as DBFs will never allow you to have more than 2GB/recsize() rows, which even for 1 byte short records is never exceeding 2 billion.

Bye, Olaf.

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

RE: Two Control in a Grid Column

(OP)
Thanks Mike, I put set exact on and the matter is solved.

How can I define the value for combo box like;

1. for sno=1 value should be "Inside/Outside"
2. for sno=2 value should be "Reverse/Surface"
3. for sno=4 value should be "Ok/Not Ok" (Sorry I mentioned Sno=3)

and so on

How can I do so?

Abbasaif

RE: Two Control in a Grid Column

(OP)
Thanks Mr. Olaf for

Quote:

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

Abbasaif

RE: Two Control in a Grid Column

>I put set exact on and the matter is solved.

Well, you very likely use the inexact string matching nature of VFP even completely unintentional, I'd keep it off and solve it in other ways, ie with adding trailing spaces in the comparison values.

Bye, Olaf.

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

RE: Two Control in a Grid Column

Quote (Olaf)

you very likely use the inexact string matching nature of VFP even completely unintentional, I'd keep it off and solve it in other ways, ie with adding trailing spaces in the comparison values.

I completely agree. If Sno can go up to 99, then you should be comparing it with a two-character string. If values below 10 contain a leading space, then compare it with, for example, ' 9' (that's a space followed by a digit). If the field has a trailing space, then comapre it with '9 ' (digit then space).

Better still, avoid all these problems by storing the field as a numeric.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Two Control in a Grid Column

(OP)
Hi,

You mean to say to I should do like this;


THIS.Column4.DynamicCurrentControl = ;
"IIF(INLIST(Job.Roll.Sno, '1 ', '2 ', '3 ', '10'), 'combo1', 'text1')"

As the length of sno is greater than 3 digit. But not I have altered with 3 digits.
I will change the field from character to numeric.

Thanks

( I will put the set exact off again ).

Abbasaif

RE: Two Control in a Grid Column

(OP)
Also, please let me know how to assign the values of combo box as follows:

1. for sno=1 value should be "Inside/Outside"
2. for sno=2 value should be "Reverse/Surface"
3. for sno=4 value should be "Ok/Not Ok" (Sorry I mentioned Sno=3)

and so on

Abbasaif

RE: Two Control in a Grid Column

The simplest way to desing a comboboc is using Rowsroucetype 1 (values) and set the value to a comma separated list of values, that map to 1 = first entry, 2= second entry etc.

Other ways exsist. Simply read in your foxpro reference on how to use a combobox. The hackers guide may be simpler to get than the VFP help and have more examples.
But a search here will also surely give you mane examples on how to populate and use a combobox.

Bye, Olaf.

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

RE: Two Control in a Grid Column

(OP)
Thanks Mr. Olaf

I will look into it.

Abbasaif

RE: Two Control in a Grid Column

(OP)
Hi

I tried to get value for combo box in column4 based on the value of column1.text ( Sno = '1')
Please look into the image.

The value is coming correct. i.e, Inside/Outside, but for 2nd column I want Reverse/Surface but it is not showing and accumulate the first row value for the combo of 2nd row.

I am using this code in the got focus event of the combo in column4.

CODE -->

Do Case
Case This.Parent.Parent.Column1.Text1.Value = '1 '
   This.AddItem("Inside")
   This.AddItem("Outside")
Case This.Parent.Parent.Column1.Text1.Value = '2 '
   This.AddItem("Reverse")
   This.AddItem("Surface")
Case This.Parent.Parent.Column1.Text1.Value = '4 '
Case This.Parent.Parent.Column1.Text1.Value = '10'
Endcase 




RE: Two Control in a Grid Column

Only addd items once in the combobox initialisation, or you get repeated items every time you click on the grid.

If you want to populate the comboobx with different items per grid row, then you first need to clear it.

A good events for that would be Grid.AfterRowColChange so you are in the current row.

Then never read from grid control.value properties, you bind the grid to workarea columns, so address JobRoll.Snom not Column1.Text1.Valu
There only is one Column1.Text1.Value and depending on when and where you read that, this will not be the value of the current row.

Bye, Olaf.

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

RE: Two Control in a Grid Column

And the biggest thing you should do: VFP is data oriented, isn't it? If the combobox items depend on the Sno, then define a table holding the combobox items as comboitems(Sno, item, itemorder) and set the items by SELECT * FROM combo WHERE comboitemsSno=JobRoll.Sno ORDER BY itemorder.

Don't write out a bid case statement that's actuelly encoding just data, use data for data.

Bye, Olaf.

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

RE: Two Control in a Grid Column

And one more thing: If Sno determines an item list for the comobobox, you also need something else to store the picked value. So Acceptance should be a field that stored the item number of the picked item and in turn also determines which item is shown. That's the combobox.controlsource.

Otherwise you have picklists but every combo will show its first item and then the picked item is not recorded anywhere.

When you're finally there you'll also notice that an Acceptance field will have the same value, say 2 for second item, even when due to different Sno you show different item lists. So only the combination of Sno and Acceptance value will in combinatin point to the one picked comboitem of the table I suggested for sno=jobroll.sno and itemorder=JobRoll.acceptance. Whether that's a good idea, I don't know, I'd rather want a simple foreign key that directly points to the item actually picked.

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