vb.net - Referencing an object using a variable string in Visual Basic 2010 -
i have several sets of similar objects (labels, progress bars) on form in visual basic 2010 on windows. in code, have collections contain data, needs pushed value/text property of each.
i solution similar php in can assign values like:
for id integer 0 count(collectionexample) lblexample{id}.text=collectionexample(variableid)
...and such loop through each of different lblexample's updated corresponding value.
the issue have come cannot seem reference object on form using variable. have tried using
callbyname("lblexample" + variableid, "text", calltype.set, examplecollection(variableid))
... still can't combine string , variable reference object.
any solutions on referring objects in vb2010 combining string prefix , variable string identifier, similar php's $variable{$variable} approach?
edit: windows platform
you add each of controls dictionary, using string key.
then can access controls using string.
here simple example, replace loop foreach loop...
there may cleaner way associate data controls, putting controls in collection indexed integer (id in example), asked string!
public class form1 dim ctrldict new dictionary(of string, control) private sub form1_load(byval sender object, byval e system.eventargs) handles me.load ctrldict.add("label1", label1) ctrldict.add("label2", label2) integer = 1 2 ctrldict("label" & i).text = "test" & next end sub end class
Comments
Post a Comment