StrataFrame Forum

How do I find length of bound field - programatically?

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

By Howard Bennett - 6/11/2007

I'm wanting to set the maxlength at run-time to the length of the bound field. 

I've got a textbox bound to a varchar(20) field.  If I want the maxlength of my textbox to be 20, how do I find out what that field's size is - in code?

By rmoore - 6/11/2007

The BO has a property called Length. You can access it by doing:

MyBO.FieldName.Length()
By StrataFrame Team - 6/12/2007

That FieldName.Length property is the actual length of the string returned by that property, so it's not going to be 20... what you want to use is the FieldLengths property.  It's a dictionary of all of the fields lengths listed by the field name.  So, set your textbox like this:

Me.myTextBox.MaxLength = Me.bo1.FieldLengths("FieldName")

By StrataFrame Team - 6/12/2007

However, rmoore is right... if you ever need to test on the length of the data in a field, you can use BO.FieldName.Length (like if you're testing for a business rule to make sure a user has entered a minimum amount of data or something.
By Howard Bennett - 6/12/2007

Thanks for your help!
By Howard Bennett - 6/12/2007

Thanks for the clarification...