Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Is it possible to have two related combos in grid?
Message
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01575781
Message ID:
01575824
Vues:
73
This message has been marked as a message which has helped to the initial question of the thread.
>>Comboboxes are hard to tame in a grid, it's very time consuming to make it work 100%. A workaround would be to add a button next to the field and when you click the button you open a separate search list (modal form). It might not be as elegant but has the advantage that it works with lots of records as all.
>
>I think I was able to make it work by making the second column not bound.

I tried something similar once, but the problem is if you change the value in the first combo, and on the valid you change the list of the second combo, that would happen for all rows in the grid. I did another trick once by adding multiple comboboxes into one column (which each have a different recordsource) and using DynamicCurrentControl to display the appropriate control based on the value in another field. That is relatively easy to accomplish but works only if you have a limited number of different values in the first combo. I think up to 10 or 15 controls could be working but the most I ever did was about 6.

Also I had always trouble when trying to use recordsource as alias. So I used a workaround to create the recordsource in code like this:
*-- Comobobox for reason of absence.
loColumn = THIS.Column12
loColumn.ControlSource = ""
loColumn.NewObject("ReasonDataEntry","Combobox")
*
LOCAL loCombobox AS Combobox
*
loCombobox = loColumn.ReasonDataentry
loCombobox.Visible = .T.
loCombobox.ColumnCount = 2
loCombobox.BoundColumn = 2
loCombobox.BoundTo = .F.
loCombobox.ColumnWidths = "160,0"
*
*-- Here get the list of records from the table (a regular USE or SELECT statement can be used if you have VFP tables).
LOCAL loSReason AS VReasonBiz OF payroll_employees_sickness_reason.vcx
loSReason = NEWOBJECT("SReasonBiz","payroll_employees_sickness_reason.vcx")
loSReason.OrderFieldName = "srDescr"
loSReason.DoGetAllRecords()
*
*-- Now add the values using AddListItem instead of using the cursor as recordsource makes the combobox
*-- behave much more nicely.
LOCAL loCounter AS lnCounter OF Utils
loCounter = NEWOBJECT("lnCounter","Utils")
*
loSReason.DoSelect()
*
SCAN
	loCounter.DoAdd()
	loCombobox.AddListItem(loSReason.srDescr,loCounter.Value,1)
	loCombobox.AddListItem(loSReason.srKey,loCounter.Value,2)
ENDSCAN
*
loColumn.Sparse = .F.
loColumn.CurrentControl = "ReasonDataentry"
loColumn.ControlSource = THIS.AliasName + ".siSrKey"
Now you can add multiple of those comboboxes with different lists and use DynamicCurrentControl() to display them individually in each row based on another field:
loColumn.DynamicCurrentControl = "ICASE(ThisAlias.OtherField=1,'ReasonDataentry',ThisAlias.OtherField=2,'OtherCombo',etc...)"
Now after changing the value in the first combo, all you need to do is a Grid.REFRESH() to make the DynamicCurrentControl switch the control for you.
Christian Isberner
Software Consultant
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform