ComboBox ItemSource problem

Moderator: Rathinagiri

Post Reply
User avatar
CalScot
Posts: 235
Joined: Thu Mar 21, 2013 12:22 am
Location: California
Been thanked: 1 time

ComboBox ItemSource problem

Post by CalScot » Wed Apr 24, 2013 5:25 am

I'm having trouble trying to show codes and their descriptions (two fields) in the drop-down of a ComboBox. The code is the one I want stored. For the record, I'm using 3.1.1 and XP SP3.

When I set up the definition as
ITEMSOURCE UCATHL->ATHLCD
everything compiles and runs perfectly, but (obviously) shows only the code.

When I change the definition to
ITEMSOURCE UCATHL->ATHLCD, UCATHL->ATHLNAME
it compiles, but then I get the following run-time error:

Program Error
Error BASE/1108 Argument error: AT
Called from AT(0)
Called from DEFINECOMBO(161)
Called from...

(Using "ITEMSOURCE UCATHL->ATHLNAME" on its own works fine, so it's a valid field.)

I've used the Combo.8 and Combo.9 samples, and they compile OK, but they don't show the codes (the first field listed) -- only the descriptions (the 2nd field listed), and no menu!, so I'm not sure what, if anything, that tells me!

Sample program is attached. It's very small -- just a few lines to open the table, index it, then load and activate the window, which has only the ComboBox in it -- but it gives me the same error; it just doesn't seem to like two fields in ItemSource!!

All thoughts and suggestions welcomed!

Tks.
CalScot
Attachments
UCATHL.ZIP
(1.67 KiB) Downloaded 82 times

User avatar
mol
Posts: 2876
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 135 times
Been thanked: 66 times
Contact:

Post by mol » Wed Apr 24, 2013 8:03 am

Hi!
What data do you want to present in ComboBox? first field, second field or both of them?

If both of them, you can join them:
UCATHL->AthlCd + UCATHL->AthlName
or
UCATHL->AthlCd - (" "+UCATHL->AthlName)
to move spaces to the end

User avatar
CalScot
Posts: 235
Joined: Thu Mar 21, 2013 12:22 am
Location: California
Been thanked: 1 time

Post by CalScot » Wed Apr 24, 2013 8:39 am

Thanks, Marek.

I want only the code in the ComboBox itself, but both the code and its description to show in the dropdown. For example, the drop-down list may show:

ABC Description for code ABC
DEF Description for code DEF
GHI Description for code GHI

but I want only ABC or DEF or GHI (i.e., the 1st field, the "Code" field) to be "saved" in the box.
(I hope that's clear?)

Tks again.
CalScot

User avatar
esgici
Posts: 4363
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Has thanked: 246 times
Been thanked: 91 times
Contact:

Post by esgici » Wed Apr 24, 2013 9:15 am

Hi Scotty
CalScot wrote: ...
ITEMSOURCE UCATHL->ATHLCD, UCATHL->ATHLNAME
it compiles, but then I get the following run-time error:
...
Since ComboBox is a single column control you can't assign more than one field to ItemSource property.

For multiple column / field GRID control may be more convenient.

Or as Marek noticed concatenate two fields into one string.

Happy HMG'ing :D
Viva INTERNATIONAL HMG :D

User avatar
CalScot
Posts: 235
Joined: Thu Mar 21, 2013 12:22 am
Location: California
Been thanked: 1 time

Post by CalScot » Wed Apr 24, 2013 3:50 pm

Thanks, esgici.

You wrote:
Since ComboBox is a single column control you can't assign more than one field to ItemSource property.
but the documentation (HMG Reference) for ComboBox shows:

Code: Select all

            ITEMS <caItems>
            ITEMSOURCE <ItemSourceField1> [ , <ItemSourceField2> ]
            VALUE <nValue>
            VALUESOURCE <ValueSourceField>
            DISPLAYEDIT <lValue>
and, from the Combo.8 sample:

Code: Select all

		DEFINE COMBOBOX Combo_2
			ROW 10
			COL 250
			ITEMSOURCE CIDADES->CODIGO , CIDADES->DESCRICAO
			VALUE 2
			WIDTH 200					
			HEIGHT 100					
			IMAGE aImages
			DROPPEDWIDTH 350
			ONDROPDOWN PlayBeep()
			ONCLOSEUP PlayAsterisk()		
		END COMBOBOX
Was it something that used to work but the feature has been taken away? Or is there some other thing that's causing it to not work? I don't know, so I'm still confused!

It certainly seems like the intention is (or was?) to have a dropdown box with 2 columns, such as a code and a full-text name for the code (with only the code being stored), as in the sample and in what I was trying to do. It would definitely be a useful thing to have and to get working!

Tks.
CalScot

PS: Also...

I think that the possibility of having the two fields in ITEMSOURCE is why the DROPDOWNWIDTH option exists: That width would need to be greater than the width of just the data in the box itself.
Sorry, but so many things point to saying that is -should- work, so I don't want to give up yet!

Tks again.
CalScot

User avatar
esgici
Posts: 4363
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Has thanked: 246 times
Been thanked: 91 times
Contact:

Post by esgici » Wed Apr 24, 2013 4:28 pm

Hi Scotty
...
Was it something that used to work but the feature has been taken away? Or is there some other thing that's causing it to not work? I don't know, so I'm still confused!
You are write, by a quick read HMG Doc and and COMBO.8 sample, its seem that its possible to define two field as ITEMSOURCE.

But as notified a little down of this doc page, at "Image Support" section, this two field notation is for Image support; not for automatically concatenate two fields nor for make a two column combobox.

In fact, with this way its possible build a two column ComboBox; but first column is for images.
It certainly seems like the intention is (or was?) to have a dropdown box with 2 columns, such as a code and a full-text name for the code (with only the code being stored), as in the sample and in what I was trying to do. It would definitely be a useful thing to have and to get working!
Sorry, but IMHO no relation exist between this issue and dropdown.

Happy HMG'ing :D
Viva INTERNATIONAL HMG :D

User avatar
CalScot
Posts: 235
Joined: Thu Mar 21, 2013 12:22 am
Location: California
Been thanked: 1 time

Post by CalScot » Fri Apr 26, 2013 4:14 am

Thanks to the replies by Marek & esgici, I have a solution. (Updated sample attached.)

The dropdown list shows the concatenated code and description fields, but only the code field shows in the box. When the data is saved, the field it is saved to is the same length as the code, so the data gets truncated, only the code is saved, and the description data is discarded.

It does mean using a different, fixed-width font, but it works. ( I wish that there was a fixed-width version of Arial !! )

Thanks again.
CalScot
Attachments
UCATHL.ZIP
(2 KiB) Downloaded 119 times

User avatar
esgici
Posts: 4363
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Has thanked: 246 times
Been thanked: 91 times
Contact:

Post by esgici » Fri Apr 26, 2013 1:46 pm

Hi Scotty
CalScot wrote:...I have a solution. (Updated sample attached.)...
Good implementation, thanks to share :)

Nonetheless GRID will be may convenient to your need, I think.

Regards
Viva INTERNATIONAL HMG :D

Leopoldo Blancas
Posts: 344
Joined: Wed Nov 21, 2012 7:14 pm
Location: México
Has thanked: 1 time
Been thanked: 4 times

Post by Leopoldo Blancas » Fri Apr 26, 2013 3:07 pm

Bonita implementación CalScot...

Gracias por compartir...
Saludos
Polo
*----------------------------------------------------------------------------------------------------------------------------
Nice implementation CalScot ...

Thanks for sharing ...
regards
Polo

Post Reply