You can use some thing like this untested code:
Dim selectedValue As String = ""
If not tsComboBox.SelectedItem is Nothing then
selectedValue = CStr(tsComboBox.SelectedItem)
End If
MsgBox("The selected value is '" & selectedValue & "'")
Hope this helps
lolafuertes
Practically a Posting Shark
890 posts since Oct 2008
Reputation Points: 164
Solved Threads: 189
Skill Endorsements: 5
Probably because the default is to declare the Modifier property of the controls in a form as Private. Change it to Public to access to its properties from another form.
Then to create the new form Form2 and show it, you need to pass the Form1 be reference to the Form2 like:
Dim f2 as new Form2(byref Form1)
f2.Show()
and in the Form2, you shoud change the
Public Sub New()
InitializeComponent()
End Sub
to
Dim F1 as Form1
Public Sub New(ByRef TheF1 as Form1)
InitializeComponent()
F1 = TheF1
End Sub
Then, later, on Form2 you can use:
F1.tsComboBox.Name
Hope this helps
lolafuertes
Practically a Posting Shark
890 posts since Oct 2008
Reputation Points: 164
Solved Threads: 189
Skill Endorsements: 5
You can use the below code, without passing anything to Form2. The menutstrip and the combobox is accessible without changing the default modifier,Friend.
Form1.tsMenu.Items("tsComboBox").Name
instead of
Form1.Controls("tsMenu").Controls("tsComboBox").Name
If you want to do more than just access the name, i.e. add more items, get selectedtext, etc., from Form2, use
Dim NewComboBox As ToolStripComboBox = DirectCast(Form1.tsMenu.Items("tsComboBox"), ToolStripComboBox)
tinstaafl
Nearly a Posting Virtuoso
1,333 posts since Jun 2010
Reputation Points: 355
Solved Threads: 234
Skill Endorsements: 14
Question Answered as of 3 Months Ago by
lolafuertes,
tinstaafl
and
xerohomicide