C
confused_newbie
Ok, I get that CF doesn't support control("name") to select and act on a
control.
I have text files that contain text I need to add to my comboboxes when the
program loads. The first line in each text file is the name of the combobox;
the rest of that text file contains the strings that need to be added
[.items.add] to that combobox.
I've tried a variety of suggestions posted in this ng, and have searched the
web and MS's FAQ as well- but I can't get anything to work.
If anyone has an easy suggestion, please let me know. Alternatively, I'm
thinking I have to cycle through the form and get the names of all the
comboboxes, and put the names of the comboboxes as indexes in a hashtable
along with the comboboxes themselves(?). However, I can't seem to find any
way to cycle through all the controls and get their name properties to start
with, e.g.
Sub GetNames
Dim MyCmb as Combobox
For Each MyCmb in Me.Controls
myHT.add(MyCmb.name, MyCmb) 'still relies on the name property-
doesn't work
Next
End Sub
another option I've tried is below, but that keeps throwing exceptions...
(watch for wrap)
Private function getcontrolbyname(byval name as string) as combobox
return directcast(me.gettype().getfield(name,bindingflags.nonpublic or
Bindingflags.public or bindingflags.instance or
bindingflags.ignorecase).getvalue(me),combobox)
end function
'paired with
Sub Testme
Dim tmpcontrol as combobox
tmpcontrol = getcontrolbyname("cmb01")
tmpcontrol.items.add ("testing")
end sub
'the sub & function above throw a managed nullreferenceexception at Frm1
getcontrolbyname+0x15
TIA !!
control.
I have text files that contain text I need to add to my comboboxes when the
program loads. The first line in each text file is the name of the combobox;
the rest of that text file contains the strings that need to be added
[.items.add] to that combobox.
I've tried a variety of suggestions posted in this ng, and have searched the
web and MS's FAQ as well- but I can't get anything to work.
If anyone has an easy suggestion, please let me know. Alternatively, I'm
thinking I have to cycle through the form and get the names of all the
comboboxes, and put the names of the comboboxes as indexes in a hashtable
along with the comboboxes themselves(?). However, I can't seem to find any
way to cycle through all the controls and get their name properties to start
with, e.g.
Sub GetNames
Dim MyCmb as Combobox
For Each MyCmb in Me.Controls
myHT.add(MyCmb.name, MyCmb) 'still relies on the name property-
doesn't work
Next
End Sub
another option I've tried is below, but that keeps throwing exceptions...
(watch for wrap)
Private function getcontrolbyname(byval name as string) as combobox
return directcast(me.gettype().getfield(name,bindingflags.nonpublic or
Bindingflags.public or bindingflags.instance or
bindingflags.ignorecase).getvalue(me),combobox)
end function
'paired with
Sub Testme
Dim tmpcontrol as combobox
tmpcontrol = getcontrolbyname("cmb01")
tmpcontrol.items.add ("testing")
end sub
'the sub & function above throw a managed nullreferenceexception at Frm1
getcontrolbyname+0x15
TIA !!