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

Combobox in grid with different RowSource for each row

sashaDG

Programmer
Jun 20, 2022
112
0
16
BY
Good afternoon, I have been a few days in a dead end with the question to which did not come a solution that was given on the forum (https://www.tek-tips.com/threads/two-control-in-a-grid-column.1798594/).
Condition Grid.init:


Code:
sparse = false,
thisform.grid_requestItems.column4.DynamicCurrentControl = ;
    "IIF(CountMeasureByKdse(dictionaryCurs, &entryReqItemsCurs..kdse) > 1,'listMeasure','txtMeasure')"
 
thisform.grid_requestItems.column4.listMeasure.RowSourceType = 3
thisform.grid_requestItems.column4.listMeasure.RowSource = "SELECT msr_name, msr_id FROM &dictionaryCurs WHERE kdse == &entryReqItemsCurs. kdse into cursor cc"


How to make the display and fixing for each entry a separate list with values in combobox.

I add the code to AfterRowChange:
Code:
thisform.grid_requestItems.column4.listMeasure.Requery
but then the display of the remaining cells may disappear.

And also to add a question: can you change the controlSourse for column for txtBox, combobox in run time?

Would appreciate any help!
 
Last edited:
I'm not going to take the time to read through your original thread.

But one thing stands out from the code you posted above. The line sparse = false, looks suspicious, for two reasons. First, the comma at the end should not be there (maybe this is just a typing error?). More importantly, Sparse is a property of the column, and so should be preceded by thisform.grid_requestItems.column4. or something similar. As things stand, this line of code will create a variable name Sparse, which is presumably not what you want.

Mike
 
I browsed through the old thread, I don't see that it would give you what you want.

Let me just add to Mikes advice, that DynamicCurrentControl is to pick a control for a cell, but it doesn't create it, so the outset would be you creating as many comboboxes as are necessary with each their own item list and adding them to the column. The field controlling the grid column in which you switch between the comboboxes will still need to be used as controlsource of the comboboxes, too, so you'll have a hard time taking the grid cursors fieldX as controlsource for a bunch of lists that each differ in themselves and point to completely different lists.

The demand you have would be a case for using something else, an ActiveX control that allows such things easier.
 
Last edited:
Sorry for the inaccuracy in the message, I mixed code from file and pseudo(sparse = falase). Actually the property sparse has been changed in design time.

I browsed through the old thread, I don't see that it would give you what you want.
Here’s about this part of the branch and its proposal as to solve from Olaf

...but it doesn't create it, so the outset would be you creating as many comboboxes as are necessary with each their own item list and adding them to the column.
Unfortunately I don’t know how to create combobox, in addition don’t know how many rows there will be in the grid. There is a plan : for the single combobox to change the data source when changing the selected record, but the problem is that is possible do not change the values in the previous records for the combobox displayvalue.

The demand you have would be a case for using something else, an ActiveX control that allows such things easier.
Not familiar with this section
 
Hi,

Sasha

Unfortunately I don’t know how to create combobox,

You may want to have a look at the demo code attached

Sasha

in addition don’t know how many rows there will be in the grid.

Comboboxes are added per COLUMN not per ROW

hth

MarK
 

Attachments

  • testgridcombobox.zip
    1.5 KB · Views: 5
Thanks for code.
Comboboxes are added per COLUMN not per ROW
Yes, I don’t know what happened to me, when wrote the message.

1724312284690.png1724312295845.png
In your example (screenshots) the data source is the same for all names. Is it possible that "Maxime" & " Geoffrey" have different data for "Office"
 
Yes, I don’t know what happened to me, when wrote the message.
You wanted to have different lists in comboboxes per record, that suggests in the most general case you could need a combobox per row. You can create them per CREATEOBJECT, ADDOBJECT, NEWOBJECT, as you create all objects. Never did that, it seems, how are you living? So you'd have several Thisform.grid1.colum4.addobject("mycombo1","combobox") to do.

MarK is still right in the sense that all these comboboxes would be added to the same grid column object, but the dynamicccurrentcontrol then would pick an individiual combobox per RECNO(), for example. It's possible in theory so far. But all these comboboxes will have the same column controlsource as their controlsource.
There is a plan : for the single combobox to change the data source when changing the selected record, but the problem is that is possible do not change the values in the previous records for the combobox displayvalue.
You identified one problem, the other one is that reusing the same combobox and changing their items dynamically from row to row is even less feasable then having as many comboboxes as you have different lists and addressing them per dynamiccurrentcontrol.

What remains in the column is usually not a picked item, but a combobox wil have a key/item combination and you display the key in sparse columns in allother rows than the active one. That's also a problem, so you'd use a cobobx that's not that way but just has rowsourcetype values, for example, where the picked value becomes the grid column value also acting as controlsource. If that works you'll just populate the grid table with texts, though, which I doubt is useful. Even if all lists are not sharing any item text and so a single item text identifies which list it belongs to, You'll generally need another column that decides which combox to use. All these aspects don't seem solvable to me elegantly.

And so ActiveX is a simpler way as there are grids by other companies that actually will allow objects per cell. Don't know any ActiveX? Well, get started by using one of the ActiveX provided by the VFP installation: Slider. You add an olecontrol to a form and then pick which one. For the slider it would be The "Microsoft Slider Control 6.0 (SP6)":
Adding an ActiveX control to a form

Well, and any ActiveX control you find from third parties, not only by MS would list here and be usable in VFP. Well known vendors of ActiveX controls that work well in VFP are DBi and Exontrol and Chilkat. The internet is your limit.
 
Last edited:
Thank you for clarifying. There is no time to learn ActiveX, so I will change the table display structure
 
You want each current control in a separate column to use its own data source if I understand you correctly.

There are usually two ways to accomplish this:
1 Use the dynamic properties of Column;
2 Using the control's BackStyle_Access method.

I usually use the second method because it's easier to implement and it's easy to encapsulate and inherit.

The screenshot is of the BackStyle_Access method of my Image base class:
myImage.BackStyle_Access
 
Hello

xinjie

Programmer​

Sep 6, 20201501[URL=']CN[/URL]
You want each current control in a separate column to use its own data source if I understand you correctly.
I want different current control(using DynamicCurrentControl and its works good) in a ONE column to use different data source depends on recno()(row grid)
 
Hi,

You need some kind of "flying" cursor as the RECORDSOURCE of the combobox. Perhaps the attached demo code will give you some hints.

Please be aware though that the underlying control MUST accept the returned values - you can't mix values of different types. Furthermore the described approach requires that for each record you'll have all the options available, which might lead to a huge lookup table/cursor.

hth

MarK
 

Attachments

  • testgridcombobox.zip
    1.6 KB · Views: 6
I want different current control(using DynamicCurrentControl and its works good) in a ONE column to use different data source depends on recno()(row grid)
What I've described is not outdated and simply requires the DynamicCurrentControl property to be used again.

It's something like this:
Code:
With Grid
    With .Column1
        .DynamicCurrentControl = "iif(Recno() = 1, "myImage", "myCombo")"
    EndWith
EndWith

An example of this technique: [URL=']Properties Window for VFP OOP Report Designer[/URL]
微信图片_20240823143805.png
 
Last edited:
Code:
Code:
With Grid
    With .Column1
        .DynamicCurrentControl = "iif(Recno() = 1, "myImage", "myCombo")"
    EndWith
EndWith

This is the same as my code above:
Code:
thisform.grid_requestItems.column4.DynamicCurrentControl = ;
    "IIF(CountMeasureByKdse(dictionaryCurs, &entryReqItemsCurs..kdse) > 1,'listMeasure','txtMeasure')"

And after I described that when you set the property Sparse = .F. and rewrite recordsource in combobox, displayvalue is changed in not focused rows, which is logical
 
Your code is similar to the one I decided to stop with.
The first - property I returned to Sparse = .T. .
second - added DynamicBackColor to column to change the color for entries that will combobox
Please be aware though that the underlying control MUST accept the returned values - you can't mix values of different types. Furthermore the described approach requires that for each record you'll have all the options available, which might lead to a huge lookup table/cursor.
 
Hi

Sasha,

Your code is similar to the one I decided to stop with.
Well then you misread it - or I don't get what you want

Btw, if SPARSE = .T. then you don't need the DYNAMICCURRENTCONTROL since only the cell that has focus activates the combobox.

hth

MarK
 
Well then you misread it - or I don't get what you want
Sorry, maybe I misread. In the file you attached Sparse = .T., and different sources for rows. This is what I’m working on now (originally wanted to have Sparse = .F. and diff sources)
 

Part and Inventory Search

Sponsor

Back
Top