How do I restrict a user to enter a parameter in a list of values ?

  • Thread starter Thread starter Alex Nitulescu
  • Start date Start date
A

Alex Nitulescu

Hi. A newbie question, please:

I have a function which gets some values from a database, based on a
CategoryName. My function looks like this:
Public Function GetProducts(ByVal CategoryName As String) As DataSet.

I would like to be able to restrict the user to enter only one of the
EXISTING categories - to behave in the same way IntelliSense behaves. For
instance if I had the categories "Category One" and "Category Two", the user
should only be able to select among one of those.

I created a module named "categories" with the intent to be able to declare
the function as
Public Function GetProducts(ByVal CategoryName As CategoriesList) As DataSet

I cannot use an enum, because I cannot enter the string "Category One" as a
valid member of the Enum (the name of the member has to be a valid VB name).

So I thought I could use a collection. I have now in a module named
"Categories.vb" a collection "CategoriesList":

Module Categories
Public CategoriesList As New Collection()
End Module

CategoriesList is filled like this:

Do While objDataReader.Read()
Categories.CategoriesList.Add(objDataReader("CategoryName").ToString)
Loop

Now my problem is how do I change the signature of my function ? If I try to
write:
Public Function GetProducts(ByVal CategoryName As CategoriesList) As
DataSet, it says that CategoriesList is not defined as a type.

What am I doing wrong, please ?

Thank you, Alex
 
Use combobox and set its dropdown property to dropdownlist. now pass
combobox1.text as string to the function :)
 
Back
Top