Get rid of the DataBind() method calls. I'll claim...err...stupidity. I do a lot of ASP.Net and you have to DataBind ASP.Net drop downs. Windows forms combos don't have a DataBind() method. They'll automatically "bind" when you set their DataSource. Pardon that - it was late...that's my excuse and I'm sticking to it! *sigh*
I'm not sure that your DropListData class is going to work as you intend. You're kind of building up your list in the class constructor and populating its internal ArrayList but I don't see that you expose that ArrayList as a property or anything - so I don't see how it's going to bind as a datasource to your combos.
While your approach *could* theoretically work if you made an accessor for your ArrayList and bound to it rather than the class itself, I'm not sure that's the approach I would take. There's nothing wrong with your approach if you can make it work. There are also a few things you could do to shorten your code - since things like lists of days, months, and years can be built using loops rather than single lines of values. Again - nothing wrong with using single lines - there are just several solutions.
I would probably make the data list class and use a seperate method (public function) for each different list (state list, year list, etc) - and each one have a return type of ArrayList. You could then make an instance of your data class and use the methods for the data sources of your combos.
For example, in your data class you might do:
Code:
Public Class DropListData
Public Function StateList As ArrayList
Dim oStateList As New ArrayList()
oStateList.Add("AZ - Arizona")
oStateList.Add("CA - California")
oStateList.Add("NM - New Mexico")
' Etc.
Return oStateList
End Function
Public Function MonthList As ArrayList
Dim oMonthList As New ArrayList()
Dim nIndex As Integer
For nIndex = 1 To 12
oMonthList.Add(MonthName(nIndex))
Next
Return oMonthList
End Function
Public Function DayList As ArrayList
Dim oDayList As New ArrayList()
Dim nIndex As Integer
Dim sDay As String
For nIndex = 1 To 31
sDay = nIndex.ToString()
If sDay.Length = 1 Then
sDay = "0" + sDay
End If
oDayList.Add(sDay)
Next nIndex
Return oDayList
End Function
Public Function YearList As ArrayList
Dim oYearList As New ArrayList()
Dim nIndex As Integer
For nIndex = (DateTime.Now.Year - 100) To DateTime.Now.Year
oYearList.Add(nIndex.ToString())
Next
Return oYearList
End Function
End Class
I went a little overboard giving examples for each method...but that's kinda my style (from the VB6 forums). *sigh* But anyways, it does show you how you can do some of your lists a little differently.
The big stickler is the list of states. There's nothing wrong with hardcoding all of the values but in actual practice a lot of times you'd pull the state list from a text file, xml doc, database, or something. If you don't have that type of data source OR you don't want extra dependencies for your application(s) then hardcoding the list is actually a good solution. Plus, in the case of a list of US states it's not very likely that the data is going to change.
To use a data list class with the methods setup differently as illustrated above in a form, you'd do something like:
Visual Basic:
Dim oDataLists As New DropListData()
ddlStates1.DataSource = oDataLists.StateList
ddlStates2.DataSource = oDataLists.StateList
ddlYears.DataSource = oDataLists.YearList
' Etc.
Now, if you wanted to make your existing data class work what you'd need to do is add a public property to your class that exposes your 'oData' ArrayList. I would also recommend making the Enum in the data list class Public - which will allow it to be used from your form (so you don't have to declare it twice - it kinda appears that you've declared it in the form too...)
Code:
Public ReadOnly Property DataList as ArrayList
Get
Return oData
End Get
End Property
...which you'd bind in your code like:
Code:
ddlState.DataSource = oStates.DataList
Paul
PS - I would also agree, after reading Robby's reply that hit while I was writing my epic reply, that I don't recommend doing all of your "work" in your data class constructor either. It's not really good OOP form. The only thing you should do in the constructor is setup stuff the class needs to do its thing - all other "work" should be contained in methods, subs, etc.