﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » StrataFrame Application Framework - V1 » Business Objects and Data Access (How do I?)  » Setting AutoAdjustmaxLength in base class</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Thu, 28 May 2026 01:36:58 GMT</lastBuildDate><ttl>20</ttl><item><title>Setting AutoAdjustmaxLength in base class</title><link>http://forum.strataframe.net/FindPost25336.aspx</link><description>I want to set the AutoAdjustMaxLength to true in my Base Class Textbox. Where is the best place to put this and also to ensure it does not fire for Text Boxes that are not bound to a Business Object</description><pubDate>Thu, 10 Dec 2009 19:10:55 GMT</pubDate><dc:creator>Ger Cannoll</dc:creator></item><item><title>RE: Setting AutoAdjustmaxLength in base class</title><link>http://forum.strataframe.net/FindPost25386.aspx</link><description>Dude, I was the one who didn't think to cast it. Actually, this opens up a whole raft of possible topics for Subclassed StrataFrame controls. I'll credit you liberally, as you deserve. And my wife needs your mailing address for the cookies...&lt;/P&gt;&lt;P&gt;Les</description><pubDate>Thu, 10 Dec 2009 19:10:55 GMT</pubDate><dc:creator>Les Pinter</dc:creator></item><item><title>RE: Setting AutoAdjustmaxLength in base class</title><link>http://forum.strataframe.net/FindPost25372.aspx</link><description>Oatmeal-chocolate chip-walnut.  :P</description><pubDate>Wed, 09 Dec 2009 22:23:56 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item><item><title>RE: Setting AutoAdjustmaxLength in base class</title><link>http://forum.strataframe.net/FindPost25371.aspx</link><description>Ha!&amp;nbsp;&lt;/P&gt;&lt;P&gt;This time of year probably gingerbread.</description><pubDate>Wed, 09 Dec 2009 19:38:08 GMT</pubDate><dc:creator>Russell Scott Brown</dc:creator></item><item><title>RE: Setting AutoAdjustmaxLength in base class</title><link>http://forum.strataframe.net/FindPost25370.aspx</link><description>Hi Greg,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; So what kind of cookies do you like...&lt;/P&gt;&lt;P&gt;Les</description><pubDate>Wed, 09 Dec 2009 19:30:38 GMT</pubDate><dc:creator>Les Pinter</dc:creator></item><item><title>RE: Setting AutoAdjustmaxLength in base class</title><link>http://forum.strataframe.net/FindPost25369.aspx</link><description>My first thought was white out....  :blink:&lt;br&gt;
&lt;br&gt;
Then I realized that I forgot that the BusinessObject property of IBusinessBindable is BusinessLayerBase and not BusinessLayer. So you need to cast it:&lt;br&gt;
&lt;br&gt;
((BusinessLayer)this.BusinessObject).FieldDbTypes[boundField] == DbType.String;&lt;br&gt;
&lt;br&gt;
I did mention that I just typed the code in the post and there might be some syntax errors....:blush:</description><pubDate>Wed, 09 Dec 2009 14:09:47 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item><item><title>RE: Setting AutoAdjustmaxLength in base class</title><link>http://forum.strataframe.net/FindPost25366.aspx</link><description>Hi Greg,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; That sure looks interesting, and if you can find a way to get rid of the little red squiggles under FieldDbTypes and FieldLengths (see attached screenshot), I'll give you a cookie&amp;lt;g&amp;gt;.&lt;/P&gt;&lt;P&gt;Les</description><pubDate>Wed, 09 Dec 2009 13:02:15 GMT</pubDate><dc:creator>Les Pinter</dc:creator></item><item><title>RE: Setting AutoAdjustmaxLength in base class</title><link>http://forum.strataframe.net/FindPost25364.aspx</link><description>The BO knows about the fields that is managing. I'd think you could test for the field length of the bound field using the FieldLengths dictionary of the bound BO. To make is generic, you could also check out the FieldDbType as well. I.e.&lt;br&gt;
&lt;br&gt;
[codesnippet]//-- This handles setting the AutoAdjustMaxLength based on if the&lt;br&gt;
//&amp;nbsp;&amp;nbsp;&amp;nbsp;TextBox is bound to a non-max varchar field&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;string boundField = string.Empty;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (!string.IsNullOrEmpty(this.BindingField))&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;boundField = this.BindingField;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if ( BusinessObject != null&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;&amp; this.BusinessObject.FieldDbTypes[boundField] == DbType.String&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;&amp; this.BusinessObject.FieldLengths[boundField] &gt; 0)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;AutoAdjustMaxLength = true; &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else { AutoAdjustMaxLength = false; }[/codesnippet]&lt;br&gt;
&lt;br&gt;
(NOTE: I just typed this out, so there could be syntax/spelling errors, but you should get the idea).&lt;br&gt;
&lt;br&gt;
You could run this as suggested in the Enter event or the EnabledChanged event. However, what really is driving this is the binding state. I'd be tempted to sub-class the control, override the BusinessObject and BindingField properties, adding an event like BindingStateChanged and then handle this in that. Of course, better yet would be for this to be built into the framework! :D</description><pubDate>Wed, 09 Dec 2009 11:48:20 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item><item><title>RE: Setting AutoAdjustmaxLength in base class</title><link>http://forum.strataframe.net/FindPost25353.aspx</link><description>Hi&amp;nbsp;Aaron,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; I changed the datatype of EventName in the RodeoEventConfiguration table to VarChar(MAX) and rebuilt the business object, and then looked at the generated class code. The MaxLength property of eventName is set to -1 at line 860 of my generated BO class. There's no event that can be handled to intercept that assignment - it's just there.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; I'm looking into how best to detect that in a subclassed StrataFrame textbox's constructor. More on this story as it develops...&lt;/P&gt;&lt;P&gt;Les</description><pubDate>Tue, 08 Dec 2009 11:27:44 GMT</pubDate><dc:creator>Les Pinter</dc:creator></item><item><title>RE: Setting AutoAdjustmaxLength in base class</title><link>http://forum.strataframe.net/FindPost25351.aspx</link><description>Hi Les,&lt;br&gt;
&lt;br&gt;
Is there any chance you could modify the textbox control to detect this at the point the MaxLength is set?&lt;br&gt;
&lt;br&gt;
Aaron</description><pubDate>Tue, 08 Dec 2009 09:27:35 GMT</pubDate><dc:creator>Aaron Young</dc:creator></item><item><title>RE: Setting AutoAdjustmaxLength in base class</title><link>http://forum.strataframe.net/FindPost25348.aspx</link><description>Hi Gerard,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; The only time you could intercept the fact that the column is based on a varchar(MAX) is at BO generation time, so I don't think you can plan to approach the problem in that way; a custom property, or additional code in one of the TextBox event handlers, is where you'll have to deal with this.&lt;/P&gt;&lt;P&gt;Les</description><pubDate>Tue, 08 Dec 2009 06:25:55 GMT</pubDate><dc:creator>Les Pinter</dc:creator></item><item><title>RE: Setting AutoAdjustmaxLength in base class</title><link>http://forum.strataframe.net/FindPost25346.aspx</link><description>Les , Aaron many thanks for your replies.&lt;/P&gt;&lt;P&gt;I have this working now ok but if the textbox source happens to be a Varchar(Max) it blows out with an eror-&amp;gt; Value of -1 is not valid for Max Length in setMaxLength method. I realise this is because it is a Varchar(max) field and no way of knowing what the max size is.&lt;/P&gt;&lt;P&gt;So&amp;nbsp; I have put in a condition to test for Multiline. This is ok as long as I have Multiline set on for Varchar(Max) fields which would normally be the case, but not necessarily always if there was a situation , where in certain circumstances, I did not want to have multiline on.&lt;/P&gt;&lt;P&gt;Is there a way to check that the TextBox source is a VarChar(Max) field. If I could do this, it would be a more definitive way of checking, rather than relying on the user interface where multiline had to be switched on .</description><pubDate>Tue, 08 Dec 2009 02:05:17 GMT</pubDate><dc:creator>Ger Cannoll</dc:creator></item><item><title>RE: Setting AutoAdjustmaxLength in base class</title><link>http://forum.strataframe.net/FindPost25343.aspx</link><description>Hi Gerard,&lt;/P&gt;&lt;P&gt;If your forms are disabled until the user clicks Add or Edit, you can also tap into the EnabledChanged event. In the event I check if the control is enabled and if the multiline property is false before setting autoadjustmaxlength. I use textboxes for notes type fields (VARCHAR(MAX) in SQL) and wasn't sure of the implications of setting autoadjustmaxlength to true for these fields which is why I ignore them.&lt;/P&gt;&lt;P&gt;This is a real nice property to have :)&lt;/P&gt;&lt;P&gt;Aaron</description><pubDate>Mon, 07 Dec 2009 15:28:52 GMT</pubDate><dc:creator>Aaron Young</dc:creator></item><item><title>RE: Setting AutoAdjustmaxLength in base class</title><link>http://forum.strataframe.net/FindPost25338.aspx</link><description>Hi Gerard,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; If you add just three lines of code&amp;nbsp;to the Enter handler of the subclassed textbox, I think it will work as you want. This is based on the code from my &lt;EM&gt;Subclassed StrataFrame TextBox&lt;/EM&gt; article at LesPinter.com:&lt;/P&gt;&lt;P&gt;&lt;FONT size=1 face="Courier New"&gt;using System; using System.Drawing;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size=1 face="Courier New"&gt;public class MyTextBox : MicroFour.StrataFrame.UI.Windows.Forms.Textbox&lt;BR&gt;{&lt;BR&gt;&amp;nbsp; public MyTextBox()&lt;BR&gt;&amp;nbsp; { Font = new System.Drawing.Font(&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "Courier New", 10F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0)));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size=1 face="Courier New"&gt;// New:&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.Enter += new System.EventHandler(this.myTextBox1_Enter);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.Leave += new System.EventHandler(this.myTextBox1_Leave); }&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size=1 face="Courier New"&gt;&amp;nbsp; private void myTextBox1_Enter(object sender, EventArgs e)&lt;BR&gt;&amp;nbsp; { ForeColor = Color.White;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; BackColor = Color.Blue;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size=1 face="Courier New"&gt;// Add the following three lines of code:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size=1 face="Courier New"&gt;&lt;FONT color=#ffff11&gt;&amp;nbsp;&lt;FONT color=#ff1111&gt;&amp;nbsp;&amp;nbsp; if&amp;nbsp;&amp;nbsp; ( BusinessObject == null)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; { AutoAdjustMaxLength = false; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else { AutoAdjustMaxLength = true; }&lt;/FONT&gt;&lt;BR&gt;&lt;/FONT&gt;&amp;nbsp; }&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size=1 face="Courier New"&gt;&amp;nbsp; private void myTextBox1_Leave(object sender, EventArgs e)&lt;BR&gt;&amp;nbsp; { ForeColor = Color.Black;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; BackColor = Color.White; }&lt;BR&gt;}&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; I've attached my working sample code. Use the enclosed script to create the SQL database "Pinter" used by the program.&lt;/P&gt;&lt;P&gt;Les</description><pubDate>Mon, 07 Dec 2009 09:25:25 GMT</pubDate><dc:creator>Les Pinter</dc:creator></item></channel></rss>