trying to fill a combobox using a generic routine in a Module in vb.net 2010. I am passing to the sub the variable formname.comboboxname and splitting it into 2, running a query and this is where I can't go further. I need to do this because I have quite a few forms and comboboxes to fill, thought a generic method in one module would be great.
I may break down and do a dataset for each combobox but this certainly should work and would be my preferred choice.
in the form code I call it with --- loadComboBoxOrHelp("FrmArchive.cmbSrcType") and this is in my module, some code is commented just to show what I have tried so far. And of course the line above the CTYPE works if I uncomment it but then its not generic. As you can guess from the name of the function, i want to fill a combobox OR a help text field but I have not done that code yet, I assume once the combobox part works I can guess out the text box part. The query will be the same, just a text box instead of combobox.
The CTYPE is my error, I am trying to do this from a module so its very generic, if I put it in the forms code of course it works. ** I took out the SQL as it was confusing the issue. I am now calling it this with loadComboBoxOrHelp(Me, cmbSrcType)
Public Sub loadComboBoxOrHelp(ByVal formName, ByVal boxName)
Try
CType(formName.Controls(boxName), ComboBox).Items.Add("ABC") 'myReader.GetString("lookupValue").ToString)
Catch ex As Exception
MessageBox.Show("Error while retrieving records on table Lookups..." & ex.Message, "Lookups Table")
Finally
If conn.State = ConnectionState.Open Then conn.Close()
End Try
End Sub
End Module