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:
01575826
Vues:
30
Thanks for your hard work, I'm going to save that code, it looks like a very smart solution.

>I've been able to achieve desired result with much simpler code. I found a very helpful message yesterday.
>
>So, this is my current implementation - the code that sets the grid:
>
>with thisform.pageframe1.pagSeatBlocks.grdSeatBlocks
>
>   .recordsource = "rsTSBlocks"
>   .rowheight = 24
>
>   .highlightstyle = 2
>*   .highlightrowlinewidth = 3
>
>   for each loColumn in .columns
>      *      loColumn.addproperty("cOriginalControlSource", m.loColumn.controlsource)
>      *      loColumn.addproperty("nOriginalWidth", m.loColumn.width)
>
>      for each loControl in m.loColumn.controls
>         if upper(m.loControl.baseclass) = "HEADER"
>            *             loControl.FontSize = 8
>            bindevent(m.loControl,"Click",thisform,"HeaderClick")
>            *!*	                    loControl.addproperty("CurrentTag","") && Adds CurrentTag property
>            *!*	                    if this.lCreateIndexes && Adds indexes on the fly
>            *!*	                        this.CreateTag (m.loControl)
>            *!*	                    endif
>         endif
>      next
>   next
>
>   with .colLevels.cboLevels
>      .rowsource = ''
>      .rowsourcetype = 3
>      .parent.controlsource = 'rsTSBlocks.LevelID'
>
>      .rowsource = "select * from csrBlockLevels into cursor csrBLvls nofilter"
>      
>   endwith
>
>   with .colSections.cboSections
>      .rowsource = ''
>      .rowsourcetype = 3
>      .rowsource = "select * from csrSections into cursor csrSect where LevelID = ?thisform.currentLevelId nofilter" 
>*      .parent.controlsource = 'rsTSBlocks.SectionID'
>	  .parent.controlsource = [(IIF(seek(rsTSBlocks.SectionId, 'csrSections','SectionId'), csrSections.SDescrip,''))]	
>   endwith
>
>
>So, note the controlsource for the column. In design time this column's property bound set to false and sparse to true (default).
>
>And this is the code I have in Grid AfterRowColChange:
>
>lparameters nColIndex
>if this.columns[m.nColIndex].name = 'colSections'
>
>	thisform.currentLevelId = rsTSBlocks.LevelId
>	local lnSectionId
>	lnSectionId = rsTSBlocks.SectionId
>	this.colSections.cboSections.requery()
>	this.colSections.cboSections.value = m.lnSectionId
>endif
>
>And this is it, it seems to work well, although I was so exhausted with all my prior unsuccessful attempts that I didn't run too many tests. But it does behave the way I want - it shows correct information as a text in all rows and when I go to that cell, it opens correct list and allows me to select the value. The value is correctly saved in the field.
>
>This is UT message that helped me
>message #1143385
>
>
>
>>>>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 column 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"
>>loCombobox.UseAutoFill = .T.
>>loCombobox.NotEdit = .F.
>>*
>>*-- 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