By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,890 Members | 1,261 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,890 IT Pros & Developers. It's quick & easy.

question with custom control and for each

P: n/a
hi,

I have a little problem with a custom control and for each
(number is an integer)
(the control names are AxCTC1 etc

Dim ctrCTI As AxCTCLib.AxCtc
For Each ctrCTI In Me.Controls <---- error here
Dim indxCTI As String = ctrCTI.Name
If indxCTI = "AxCtc" & number Then
ctrCTI.AssignDevice = number
End If
Next

if i do this it brings up an error in For Each etc.
'System.InvalidCastException'
the conversion is not possible

i dunno what I should write "me.controls" is not allowed for that
control i think. it works for textboxes or anything else. the strange
thing is when i do dim ctrCTI as control it shows up. but in this case
" ctrCTI.AssignDevice = number" doesnt work anymore because its a
special value of this control and not a default ms control .

thanks for help
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Cor
Hans,
"> Dim ctrCTI As AxCTCLib.AxCtc
For Each ctrCTI In Me.Controls <---- error here
Dim indxCTI As String = ctrCTI.Name
If indxCTI = "AxCtc" & number Then
ctrCTI.AssignDevice = number
End If
Next

Me.Controls means a control on the form.
You can you AxCTClib.controls

Maybe it helps (I am absolute not sure but you need to have the parent of
the control)

If not,
You can put somewhere in your application
MessageBox.Show(Acontrolname.Parent.Name)
Then you know the name of the parent

I am not sure of this, I never did this but looks logical to me.
Otherwise Herfried willl have a solution, because I think this has something
to do with conversion from VB6 to VB.net.
On the otherhand when it not works like I said, you can to speed it up and
it is upgrading ask this in the special newsgroup for upgrading.
Microsoft.public.dotnet.languages.vb.upgrade

Cor
Nov 20 '05 #2

P: n/a
Guten Morgen Hans,

Me.Controls is a Collection of Controls. If you get an error it's because
one of the Controls in Me is not an AxCTCLib.AxCtc.

You must either ensure that Me.Controls only contains AxCTCLib.AxCtcs. Or
you must use Object for your ForEach and check the type:

If ctrCTI Is AxCTCLib.AxCtcs Then
... Name ... Number ..
End If

Regards,
Fergus
MVP [Windows Keyboard, PC Power Switch]
Nov 20 '05 #3

P: n/a
"hans.werner" <ha*********@meusburger.cc> schrieb
hi,

I have a little problem with a custom control and for each
(number is an integer)
(the control names are AxCTC1 etc

Dim ctrCTI As AxCTCLib.AxCtc
For Each ctrCTI In Me.Controls <---- error here
Dim indxCTI As String = ctrCTI.Name
If indxCTI = "AxCtc" & number Then
ctrCTI.AssignDevice = number

End If
Next

if i do this it brings up an error in For Each etc.
'System.InvalidCastException'
the conversion is not possible

i dunno what I should write "me.controls" is not allowed for that
control i think. it works for textboxes or anything else. the
strange thing is when i do dim ctrCTI as control it shows up. but in
this case " ctrCTI.AssignDevice = number" doesnt work anymore because
its a special value of this control and not a default ms control .

thanks for help


Dim ctrCTI As object
'...

For Each ctrCTI In Me.Controls
If TypeOf ctrCTI Is AxCTCLib.AxCtc Then
Dim c as AxCTCLib.AxCtc
Dim indxCTI As String
c = directcast(ctrCTI, AxCTCLib.AxCtc)
indxCTI = c.Name
If indxCTI = "AxCtc" & number Then
c.AssignDevice = number
End If
End If
Next

Not each control is an "AxCTCLib.AxCtc" control. The for-each-next loop
processes all objects and assigns them to ctrCTI. When assigning a control
that's type is not AxCTCLib.AxCtc, an error occurs.
--
Armin

Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.