0

I have a form that creates a row of checkboxes depending on the type of analysis the user wants to perform on the incoming file. I need to be able to determine if the checkbox is "checked" but I don't know how to do that when the controls are created at runtime.

So right now I have a loop going through all the controls on the form and selecting the appropriate case: for instance chkbox1, combobox1, etc. Now I can access the values of the control by using

Me.Controls.Item(chkbox1)

but after that the only thing resemebling checked is .Text which wouldn't be accurate.


So my question is: how do you workaround the .Checked property of a checkbox when it is created at runtime?

2
Contributors
2
Replies
9
Views
7 Years
Discussion Span
Last Post by Tweed
0

You have to cast the items to the checkbox type in order to access its abilities.

Use:

CType(Me.Controls.Item(chkbox1),CheckBox)

or

DirectCast(Me.Controls.Item(chkbox1),CheckBox)

or

TryCast(Me.Controls.Item(chkbox1),CheckBox)

If you have other controls, then you need to do a check before you cast:

For each ctrl as control in me.controls
if TypeOf(ctrl) is CheckBox then
'case and do work here
end if
next

Note: Aircoded.

Hope this helps.

Edited by Stevoni: n/a

0

Thank you. I just used the first one and it worked like a charm. In the future I'll use what you posted last to make it uniform.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.