StrataFrame Forum

How can I get a list of columns (properties) in BO?

http://forum.strataframe.net/Topic9292.aspx

By Ben Hayat - 6/4/2007

I've looked in the help and can't find a list collection of all the columns/properties that were mapped from table to BO.



I would like to populate a combobox.Items collection with this list. Can you tell me where I can get this list?

This might be a .Net question, but an answer would help a lot!



Thanks!
By Ben Hayat - 6/4/2007

Ok, there is a list property Fieldnames of each BO.



I tried to iterate through it but no luck:

foreach (string f in BO.StoreBO.StoreBOFieldNames)

{

comboBox1.Items.Add(f);

}

}
By Ben Hayat - 6/4/2007

never mind the last bracket, cut & paste mistake!
By Trent L. Taylor - 6/4/2007

A BO has a property called AllFIeldsList that contains all of the fields that belong to the BO.  You can enumerate it like this:

'-- Establish Locals
    Dim lcAllFields As String = ""
    For Each lcField As String In Me.MyBO.AllFieldsList.ToArray()
        lcAllFields &= lcField & ControlChars.CrLf
    Next
    MsgBox(lcAllFields)
By Ben Hayat - 6/4/2007

Thanks Trent;



I'm glad you gave me that code snippet. I'd have missed the "ToArrey" method!
By StrataFrame Team - 6/5/2007

You shouldn't have to use the ToArray() to do a For Each on the AllFieldsList... it already implements the IEnumerable and IEnumerable<string> interfaces.

Also, if you need any of the other collections, you can check out the shared constructor for a business object (located in the designer file) and you can see the collections that are created for each BO class, such as FieldLengths, FieldDbTypes, FieldNativeDbTypes, AllFieldsList, etc.

By Ben Hayat - 6/5/2007

You shouldn't have to use the ToArray() to do a For Each on the AllFieldsList... it already implements the IEnumerable and IEnumerable interfaces.


Ben, I wanted to ask Trent that question why I need to use ToArray().

However, I was trying to get that list, put it into a ComboBox and have the user select the field and I'll do Sort on it. At first I tried to assign BO.AllFieldList to ComboBox.Items and didn't like it and I ended up doing the following way:



foreach (string f in storeTaxBO.AllFieldsList.ToArray())

{

comboBox1.Items.Add(f);

}



How else could I have done this but using ForEach?

Thanks!
By Ben Hayat - 6/5/2007

Also, if you need any of the other collections, you can check out the shared constructor for a business object (located in the designer file) and you can see the collections that are created for each BO class, such as FieldLengths, FieldDbTypes, FieldNativeDbTypes, AllFieldsList, etc.




I just got to see under the hood. Very nice!



I still don't understand why I couldn't assign from that list to ComBox.Items? In Delphi, I can make that assignment without any problem!
By StrataFrame Team - 6/6/2007

The items collection is special... you can manually add to it, but it's readonly, so you cannot create a new ComboBox.ItemCollection and set it to the value.  You can, however, set it as the DataSource of the ComboBox.

myCombo.DataSource = myBo.AllFieldsList;

Should work the way you want it to.  If the collection contains complex objects, then you will need to set the DisplayMember and ValueMember properties to tell the ComboBox what property on the complex field to use for each of those, but since your item type is a string, you can just leave the DisplayMember and ValueMember fields blank.

By Ben Hayat - 6/6/2007

myCombo.DataSource = myBo.AllFieldsList;




Never thought of that myself! Smile