message warning and combo boxes

Post

Posted
Rating:
#1 (In Topic #1337)
Regular
theyikes is in the usergroup ‘Regular’
Ok I've had a quick look at the beginners section of this forum, I'm actually quite embarrassed to ask this but it's got me scratching my head. Essentially what i want to do is have a combobox with 3 items so when i select one of those items and i press the command button i'll get a popup message telling me which Item I've selected. Ok so i figured out that bit. Here's where I'm getting stuck.

Public Sub Form_Open()

  ComboBox1.Add("test 1")
ComboBox1.Add("test 2")
ComboBox1.Add("test 3")
End

Public Sub Button1_Click()
ComboBox1.Select
Message.Warning(ComboBox1.Selected)
End

Public Sub ComboBox1_Click()

  ComboBox1.Select

End

AM i even close to figuring it out yet?
Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’
you should read the wiki.

/comp/gb.qt4/combobox - Gambas Documentation

ComboBox.Select is for selecting text in the editing TextBox  (if you want only a drop down list that does not use a TextBox you must set the ComboBox.ReadOnly to True)

ComboBox.Index is for checking the current item
/comp/gb.qt4/combobox - Gambas Documentation

Your ComboBox1_Click event is not needed, just this..

Code (gambas)

  1. Public Sub Button1_Click()
  2.  
  3.   Message.Info("ComboBox1 item " & ComboBox1.Index & "  is " & ComboBox1.Text)
  4.  
  5.  

Or maybe like this via the List array..

Code (gambas)

  1.  
  2. Public Sub Button1_Click()
  3.  
  4.   Dim sText As String = Combobox1.List[Combobox1.Index]
  5.  
  6.   Message.Info("ComboBox1 item " & ComboBox1.Index & "  is " & sText)
  7.  
  8.  
Online now: No Back to the top

Post

Posted
Rating:
#3
Regular
theyikes is in the usergroup ‘Regular’
 I don't believe it i was almost there with the string option. Thanks a million for the quick response!
Online now: No Back to the top
1 guest and 0 members have just viewed this.