Combobox hidden value

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

Combobox hidden value

Post by jalz » Wed Mar 05, 2014 12:18 am

Hi all,
I have a Combo box which I'm populating with values from a database. This seems to be working great, the combo box displays values for title, firstname and surname. When I select this value, I also want to populate the email that belongs to that contact in a second field called contact_email.

My initial thought was to add the email field into the select a the 4th item and then split the pItemName and put the value into the contact_email field. This would be fairy easy, but I don't like the idea of having the email address being displayed in the drop down list when I go to pick my contact.

Is there a way of hiding this email value, perhaps making the text white when selection is taking place? or is there another more efficient way of get the email field populated with the correct address.

Ive included my code below to show you what Ive done so far already.

Thanks

Code: Select all

global gConnID, gList1

on MouseDown
   If gConnID is a integer then
      
      put label of button "cb_supplier_id" into tSupplierID
      
      put "SELECT title, firstname, lastname FROM supplier_contact WHERE supplierID=" & tSupplierID into tTheSQLQuery
      put revDataFromQuery(space, return, gConnID, tTheSQLQuery) into tTheComboBoxData 
      
      set itemdelimiter to tab
      
      put empty into gList1
      
      repeat for each line tABC in tTheComboBoxData 
         put item 1 of tABC&cr after gList1
      end repeat
      
      If gList1 is not empty then
         set the text of button "cb_supplier_contact" to gList1
      else
         set the text of button "cb_supplier_contact" to "no contacts"
      end if
      
   end if
end MouseDown

on MenuPick pItemName
   
   split pItemName by comma
  
   
     if (gConnID > 0) then
      put "SELECT email " &\
      "FROM supplier_contact " &\
      "WHERE title=" & pItemName[1] & " firstname=" & pItemName[2] &  " lastname=" & pItemName[2] into tTheSQLQuery
      put revDataFromQuery(tab, cr, gConnID, tTheSQLQuery) into tTheData
      
      if tTheData begins with "revdberr," then
         delete item 1 of tTheData
      else
         set ItemDel to tab
         put item 1 of tTheData into field "fld_supplier"

end MenuPick

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10333
Joined: Wed May 06, 2009 2:28 pm

Re: Combobox hidden value

Post by dunbarx » Wed Mar 05, 2014 3:19 am

Hi.

Might you load the actual values into a custom property of the comboBox, and only load an abbreviated, coded or truncated list into the contents? So you might have this in the menu:

Joe
Fred
John

But this in the custom property:

JoePhone,JoeAddress,JoeOtherdata
FredPhone,FredAddress,FredOtherdata
JohnPhone,JohnAddress,JohnOtherdata

Then when you choose a line in the menu, you can extract, say, the second item in the corresponding line in the property. Choosing "Joe" in the menu would return "JoeAddress" from the property. Anyway, that sort of thing.

Craig Newman

jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

Re: Combobox hidden value

Post by jalz » Wed Mar 05, 2014 8:44 am

Hi Craig

Ahhh custom properties. Someone has suggested custom property before, but couldn't get it working, so didn't use it to solve a problem I had before. I'll attempt it again see if I can get it working this time, and post my code if I get stuck … I want to understand how to use these CP's.

Thanks

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10333
Joined: Wed May 06, 2009 2:28 pm

Re: Combobox hidden value

Post by dunbarx » Wed Mar 05, 2014 3:41 pm

Hi.

Make a comboBox. Put this into its script:

Code: Select all

on menuPick
answer the menuHistory of me -- to see the line slelected
   answer line (the menuHistory of me) of the whatDoYouKnow of me -- to see the line in the property
end menuPick
Now make a button. Put this into its script:

Code: Select all

on mouseUp
   set the whatDoYouKnow of btn 1 to "You chose 1" & return & "You chose 2" & return & "You chose 3" 
end mouseUp
Click the button, then select a line in the combo. If you feel like it, in msg, execute:

answer the whatDoYouKnow of btn "yourComboBox" -- whatever reference to that combo you choose...

You can probably think up a more intelligent property name than "whatDoYouKnow"

Craig

jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

Re: Combobox hidden value

Post by jalz » Wed Mar 05, 2014 9:23 pm

Hi Craig,

Thanks, I've got it working ….. just testing out the code over different scenarios.

All the best

Jalz

Post Reply