[Gambas-user] two combobox combined in gambas

john david weston david at ...2458...
Sun Jul 11 00:37:28 CEST 2010


On Sat, 2010-07-10 at 14:55 -0400, Tomas Rodriguez wrote:
> Hi
> I would like what Can I do for get all item from a database to a combobox 
> and the other one comboxo show only item belong to the item in the first 
> combobox.
> example:
> the first combobox is for show all province of canada but the second 
> combobox show only the town belong the selected province in the first 
> combobox.
> example
> Ontario--------> Ottawa, Toronto, London, Missisigua
> 
> somebody can help me with this? or give me  a hand
> thanks
> tomas
> 
I have done this some time ago on an older version of Gambas, so I'm not
sure if this still works. It's part of a CD database which does what you
want with Artists and CD titles.  here's some snippets from my code:
(you obviously need to open the database connection first. the
load_artists() is run from Form_Open() )

PRIVATE SUB load_artists()
  
  resArtists = global.conn.Find("Artists", "ID < 629 OR ID > 630 ORDER
BY artist")
  
  FOR EACH resArtists
    cbArtists.Add(resArtists!artist)
    
  NEXT 
  
  global.writing = TRUE 'disable _change event handler to prevent
infinite loops. 
  cbArtists.Text = "< Select an Artist >"
  sCurrentArtist = ""
  sCurrentTitle = ""
  global.writing = FALSE
  btnNewTitle.Enabled = FALSE
  
END 

 
PRIVATE SUB load_titles()
  
  resArtists.MoveFirst
  resArtists.MoveTo(cbArtists.Index)
  resTitle = global.conn.Find("CDSets", "artistid = &1 ORDER BY title",
resArtists!ID)
  cbTitles.Clear
  sCurrentTitle = ""
  
  IF resTitle.Count > 0 THEN 
  
    FOR EACH resTitle
      cbTitles.Add(resTitle!title)
      
    NEXT 
  
    btnNewTitle.Enabled = TRUE
    
  ELSE 'no titles found
  
    global.writing = TRUE
    cbTitles.Text = "<ERROR No Titles Found >"
    global.writing = FALSE
    btnNewTitle.Enabled = FALSE
    
  ENDIF 
END


PUBLIC SUB combo_LostFocus()
  
  SELECT CASE LAST.Name
  
  CASE "cbArtists"
   
      sCurrentArtist = cbArtists.Text
      load_titles      
    
  CASE "cbTitles"
    IF cbTitles.text THEN 
      sCurrentTitle = cbTitles.Text
           
    ENDIF 
       
  END SELECT 
  
END


Hope this is of some help, or maybe some of the experts here can pick
holes in it or suggest a better way?

David.





More information about the User mailing list