[Beginology VB.NET] How to control controls through the name of the control

xiaoxiao2021-03-06  122

Imports system.reflection

DIM I as integer

DIM NameStr as String

For i = 0 to dataset_system.tables ("company"). Columns.count - 1

NameStr = ""

NameStr = "txt_company_" & dataset_system.tables ("company"). Columns.Item (i) .caption

Dim t as type = me.gettype

Dim f as FieldInfo = T.Getfield ("_" & namestr, bindingflags.nonpublic or bindingflags.instance or bindingflags.public)

If DataSet_system.tables ("company"). Columns.Item (i) .caption = "International Society" THEN

DIM MyControl as checkbox = ctype (f.getValue (me), checkbox)

MyControl.Enabled = CHG

Else

DIM MyControl as textbox = ctype (f.GetValue (me), Textbox)

MyControl.Enabled = CHG

END IF

NEXT

-------------------------------------------------- -------------------------------

FieldInfo overview

Public property

转载请注明原文地址:https://www.9cbs.com/read-99990.html

New Post(0)