B4J Question B4xComboBox in CustomDialog

udg

Expert
Licensed User
Longtime User
Hi all,

this one is harder to explain. It refers to the proper way to address a B4xComboBox object in code. Let's start with some code:
B4X:
Dim xui As XUI
dialog.Initialize(frm.RootPane)
Dim p As B4XView = xui.CreatePanel("")
p.SetLayoutAnimated(0, 0, 0, 700dip, 550dip)
p.LoadLayout("lytTest")                                        'Main
Log(p.NumberOfViews)                                         '10. Correct. 5th view is a B4xComboBox
'Dim cb As B4XComboBox = p1.GetView(4)               'doesn't work due to type mismatch
Dim cb As B4XComboBox
cb.Initialize(Null,"")                                              'needs to init even if the view is from Designer
cb.cmbBox = p.GetView(4).GetView(0)
'another way is
'cb.mBase = p.GetView(4)
'cb.cmbBox = cb.mBase.GetView(0)   
cb.SetItems(Array As String("one","two","three","four","five","six"))
cb.SelectedIndex = -1
dialog.PutAtTop = True 'put the dialog at the top of the screen
Dim rs As ResumableSub =  dialog.ShowCustom(p, "OK", "", "CANCEL")
...
So, although I'm referring to a view added by the Designer, I need to init my local var (types match).

Note: seems that SetItems sets the SelectedIndex to 0
 
Top