Setting AutoAdjustmaxLength in base class


Author
Message
Les Pinter
Les Pinter
StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)
Group: Forum Members
Posts: 43, Visits: 213
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...

Les

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Oatmeal-chocolate chip-walnut. Tongue
Russell Scott Brown
Russell Scott Brown
StrataFrame User (278 reputation)StrataFrame User (278 reputation)StrataFrame User (278 reputation)StrataFrame User (278 reputation)StrataFrame User (278 reputation)StrataFrame User (278 reputation)StrataFrame User (278 reputation)StrataFrame User (278 reputation)StrataFrame User (278 reputation)
Group: Forum Members
Posts: 124, Visits: 597
Ha! 

This time of year probably gingerbread.

Russ Brown (Using C#2010/SQL Server 2008)

Les Pinter
Les Pinter
StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)
Group: Forum Members
Posts: 43, Visits: 213
Hi Greg,

   So what kind of cookies do you like...

Les

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
My first thought was white out.... Blink



Then I realized that I forgot that the BusinessObject property of IBusinessBindable is BusinessLayerBase and not BusinessLayer. So you need to cast it:



((BusinessLayer)this.BusinessObject).FieldDbTypes[boundField] == DbType.String;



I did mention that I just typed the code in the post and there might be some syntax errors....Blush
Les Pinter
Les Pinter
StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)
Group: Forum Members
Posts: 43, Visits: 213
Hi Greg,

   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<g>.

Les

Attachments
Snap1.gif (138 views, 22.00 KB)
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
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.



//-- This handles setting the AutoAdjustMaxLength based on if the

//   TextBox is bound to a non-max varchar field

    string boundField = string.Empty;

    if (!string.IsNullOrEmpty(this.BindingField))

    {

      boundField = this.BindingField;

    }

    if ( BusinessObject != null

       && this.BusinessObject.FieldDbTypes[boundField] == DbType.String

       && this.BusinessObject.FieldLengths[boundField] > 0)

        AutoAdjustMaxLength = true;

    }

    else { AutoAdjustMaxLength = false; }




(NOTE: I just typed this out, so there could be syntax/spelling errors, but you should get the idea).



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! BigGrin
Les Pinter
Les Pinter
StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)
Group: Forum Members
Posts: 43, Visits: 213
Hi Aaron,

   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.

   I'm looking into how best to detect that in a subclassed StrataFrame textbox's constructor. More on this story as it develops...

Les

Aaron Young
Aaron Young
StrataFrame User (437 reputation)StrataFrame User (437 reputation)StrataFrame User (437 reputation)StrataFrame User (437 reputation)StrataFrame User (437 reputation)StrataFrame User (437 reputation)StrataFrame User (437 reputation)StrataFrame User (437 reputation)StrataFrame User (437 reputation)
Group: StrataFrame Users
Posts: 277, Visits: 1.1K
Hi Les,



Is there any chance you could modify the textbox control to detect this at the point the MaxLength is set?



Aaron
Les Pinter
Les Pinter
StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)
Group: Forum Members
Posts: 43, Visits: 213
Hi Gerard,

   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.

Les

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search