Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Combobox confusion

Posted on 2010-11-09
2
Medium Priority
?
411 Views
Last Modified: 2012-06-21
Hi Experts,

I'm trying to populate a combobox with two fields from one table and then save a value to another table.

ControlSource=Table2.Field1
RowsourceType = 6 (Fields)
Rowsource = Table1.Field1,Field2
BoundColumn=2
BoundTo = .T. (I've also tried .F.)
ColumnCount=2
ColumnWidths=0,125
Style = 2 - Dropdown List


The Rowsource table is just an index field and a description, both character fields.


Rowsource Table

Field1       Field2

01            Choice1
02            Choice2
03            Choice3
04            Choice4


I want the combobox to display Table1.Field2 and when a selection is made I want to store Table1.Field1 to Table 2.

What's happening is that nothing initially displays in the combobox. When I click on it, I see the items from Table1.Field2, as I should. But when I click on an item, I see the value from Table1.Field2. That is the value I want to store in Table 2, but I don't want to display it in the combobox after I make a selection.

For instance, when I click on the combobox I see Choice1, Choice2, etc. But when I select one of them, I see 01, 02, etc., which is what I want to store in Table 2, but not display in the combobox.

If it makes a difference, both tables are buffered,3.

I've tried using the Builder, with the same results. Any ideas? I've been at this for two days now.
0
Comment
Question by:stanmurphy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 43

Accepted Solution

by:
pcelba earned 2000 total points
ID: 34098116
Yes, to do it properly is a nightmare sometimes...

I've found interesting behavior: When you define the ControlSource then Combo value contains unexpected (but usabe) values...

After some investigations my Combo has following properties:

RowSourceType = 2 (Alias),
RowSource is a cursor having the first column displayed in Combo (so it is the description column) and the second column is the binded one (the numeric key).
BoundColumn = 2
ControlSource  is undefined
ColumnCount = 0  (default)

Refresh method synchronises the Combo value to data, InteractiveChange assigns the selected value into data.

I am saving the Combo value into a form property with the same name as the combo itself. To change this code for "Table ControlSource" by REPLACE command should be easy:

*-- Refresh method
LOCAL lnArea, lnID

lnArea = SELECT(0)
SELECT (THIS.RowSource)

lnID = EVALUATE("THISFORM.DataRecord." + ALLTRIM(THIS.Name))  && value of "ControlSource"

IF ID <> lnID OR EMPTY(THIS.DisplayValue)
  LOCATE FOR ID = lnID
  IF FOUND()
    THIS.DisplayValue = EVALUATE(FIELD(1))  && description field value
  ELSE
    THIS.DisplayValue = ""
  ENDIF
ENDIF

SELECT (lnArea)


*-- InteractiveChange method
IF TYPE('THIS.Value') = "C"
  STORE VAL(THIS.Value) TO ("THISFORM.DataRecord." + THIS.Name)  && REPLACE command for "Field ControlSource"
ELSE
  STORE THIS.Value TO ("THISFORM.DataRecord." + THIS.Name)
ENDIF

Open in new window

0
 

Author Closing Comment

by:stanmurphy
ID: 34098208
I was hoping I was just missing some setting in the combobox, but I think I knew I'd have to use some code somewhere.

Thank you very much!!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question