Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I explicitly interact with control while indexing 1

Status
Not open for further replies.

faust13

Programmer
Aug 7, 2001
176
US
I'm trying to index through an array of controls, I can find the control I am looking for. However, when I try to interact with the control, .Net doesn't seem to understand the control I am referencing.

It works fine if the control is textbox, but in this case it is a combobox. Am I missing something.

Here's my code:

Dim i, j As Integer

For i = 0 To (TabControl2.TabCount - 1)
If TabControl2.TabPages(i).Name.IndexOf(tabName) <> -1 Then
For j = 0 To (TabControl2.TabPages(i).Controls.Count - 1)
If TabControl2.TabPages(i).Controls(j).GetType.ToString.IndexOf(&quot;ComboBox&quot;) <> -1 Then

MsgBox(&quot;Found the combo box: &quot; & TabControl2.TabPages(i).Controls(j).Name.ToString)

'Now, let's set the combobox selectedindex
'This is where it breaks. .Net throws a compilation error here
TabControl2.TabPages(i).Controls(j).selectedIndex = 1
End If
Next
End If
Next --------------------------------------
Is George Lucas Kidding...
Noise Core: 7.62
 
Try
DirectCast(TabControl2.TabPages(i).Controls(j),ComboBox).selectedIndex = 1
OR
CType(TabControl2.TabPages(i).Controls(j),ComboBox).selectedIndex = 1
OR
CType(TabControl2.TabPages(i).Controls(j),object).selectedIndex = 1

Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
John,

I used:

CType(TabControl2.TabPages(i).Controls(j),ComboBox).selectedIndex = 1

It worked perfectly. Thanks for your help!

Cheers --------------------------------------
Is George Lucas Kidding...
Noise Core: 7.62
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top