vb.net - iterating by controls enclosing object


i have form "clear" button.



when user clicks "clear", i wish pristine value manifest elements form. box date controls, i wish reset tide date.



all controls contained panel.



right now, i'm doing next code. there an easier proceed manually checking any control type? slight seems excessively unwieldy.



to matters worse, method recursively pristine controls inside sub-containers (i.e., organisation box within panel) i have repeat whole monster an overloaded "groupbox" version.



edit: interjection your suggestions, next formula severely simplified.



private servant btnclear_click(byval sender system.object, byval e system.eventargs) handles btnclear.click
'user clicks clear, pristine controls within panel
clearallcontrols(panmid, true) 'true indicates yes, i wish recurse by sub-containers
end sub

clearallcontrols(byref enclosing panel, discretionary recurse boolean = true)
'clear controls within enclosing object
'if "recurse" true, following also pristine controls within any sub-containers
low ctrl control
any ctrl container.controls
(ctrl.gettype() gettype(textbox)) then
low txt textbox = ctype(ctrl, textbox)
txt.text = ""
finish if
(ctrl.gettype() gettype(checkbox)) then
low chkbx checkbox = ctype(ctrl, checkbox)
chkbx.checked = false
finish if
(ctrl.gettype() gettype(combobox)) then
low cbobx combobox = ctype(ctrl, combobox)
cbobx.selectedindex = -1
finish if
(ctrl.gettype() gettype(datetimepicker)) then
low dtp datetimepicker = ctype(ctrl, datetimepicker)
dtp.value = now()
finish if

recurse then
(ctrl.gettype() gettype(panel)) then
low pnl quarrel = ctype(ctrl, panel)
clearallcontrols(pnl, recurse)
finish if
ctrl.gettype() gettype(groupbox) then
low grbx groupbox = ctype(ctrl, groupbox)
clearallcontrols(grbx, recurse)
finish if
finish if
next
end sub


@theraccoonbear: i your suggestion, nonetheless i change chapter this:



private servant clearallcontrols(byref controls controlcollection, discretionary byval recurse boolean = true)


then line gives me "unable ban vigilant form 'controlcollection' form 'controlcollection'.":



  clearallcontrols(panmid.controls)


Comments

Popular posts from this blog

list macos calm editors formula editors

how i practical urls indicate .aspx pages asp.net deployed an iis? (preferably but iis)

jaxb - xjc - reworking generated typesafe enum category members