Help me out - data binding and custom business objects
Ok people, I need a hand with this .NET 2.0 code.
I've got a CBO to represent an bin (for putting stuff in) in my company's warehouse. My bin object has 10 or so properties and I've got a collection of them which inherit from ArrayList so I can bind some combo boxes and list boxes to the collection of my CBO. This works beautifully, although not as speedy as I'd hoped.
Here's the problem. One of my CBO properties is an array of strings. When I pull from the database, the value is a single row of space delimited characters. I take this row and turn it into it's own arraylist turning:
"CD DV UV BC DO MK"
into
The problem is this. I want to take these values and perform an additional database lookup to turn the array into this:
CD | Compact Disk
DV | DVD Video
UV | Used Video
BO | Books/Magazines
EL | Electronics
MI | Musical Instrument
So here's what my code looks like:
I've got a BinCollection object, a Bin object, and a BinConfig object. My BinCollection object has a method, "GetValidBins" which executes a stored proc to retrieve the IDs of the bins I need to return to the user. It iterates through these IDs, creating and adding Bins to the collection. When a Bin is created (with a passed in ID), it's property values are initialized via a lookup to the DB. When it goes to assign the value for it's configuration settings to the _alphaConfig property, it passes the string to a function which turns the space delimited string into an array of strings. If I stop here, everything works. My issue is that I need to bind a listbox to the _alphaConfig property when a user selects the Bin ID from a dropdown list. So, instead of a simple array of strings, I've typed my _alphaConfig property as an ArrayList. This also works, and I can bind my listbox...until...I try to perform an additional action on the values - appending the English description to the 2 character code. Here is my code (VB.Net 2.0)
''' <summary>
''' Takes the DB formatted AlphCfg list of Alpha Configurations for bins and turns
''' it into a bindable arraylist with English descriptions.
''' </summary>
''' <param name="alphaConfigs">a space delimited list of alphaConfigs (ex. CD DV EL MI)</param>
''' <returns>a bindable ArrayList of bin configs with English descriptions</returns>
''' <remarks></remarks>
Public Function DBListtoBindableList(ByVal alphaConfigs As String) As ArrayList
' break up the list of configs to get an array of individual configs
Dim myBindableConfigs As ArrayList = StringHandlers.ReturnList(alphaConfigs)
' ' connect to the database
' Dim db As Database = DatabaseFactory.CreateDatabase ' yes, I'm using the EnterpriseLibrary v 2.0
' Dim i As Integer = 0
' For Each config As String In myBindableConfigs
' Dim sqlCommand As String = StringHandlers.StringRecompost(SQLStatements.SELECTSINGLEALPHACONFIG, config) ' builds my select statement
' Dim dbCommand As DbCommand = db.GetSqlStringCommand(sqlCommand)
' Dim dbResult As DataSet = db.ExecuteDataSet(dbCommand)
' For Each row As DataRow In dbResult.Tables(0).Rows
' myBindableConfigs.Item(i) = row.Item(0).ToString
' i += 1
' Next
' Next
Return myBindableConfigs
End Function
If I uncomment the code above, I get InvalidOperationExceptions every time I try to make a change to the ArrayList value and it tells me that I'm breaking it's ability to be bindable. If I catch and handle the InvalidOperationExceptions (to keep the program running) I find that I have, indeed, broken the bindability of my list (but it does have the values I wanted).
Help!
-- Matt Ranlett