473,473 Members | 2,032 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Helper Function - TextBox MaxLength to DataColum MaxLength

Echooff3
22 New Member
Hi All,
The one weird thing I noticed about VS2005 is that you can create a dataset via a table adapter and you can drag in the fields in design time to the form, yet the maxlength on the text field remains at the default 32767. Instead of sizing itself to the size of the datacolumn it was mapped to.

I don't know if this bugs anyone else, or perhaps I missed something and it does do this automatically but here's a helper function I created that sets the sizes programmatically.

Expand|Select|Wrap|Line Numbers
  1. Public Sub SizeTextFields(ByRef pForm As Form, ByVal pDT As DataTable)
  2.         Dim ctl As Control
  3.         Dim ctlTxt As TextBox
  4.  
  5.         For Each ctl In pForm.Controls
  6.             If TypeOf ctl Is TextBox Then
  7.                 ctlTxt = ctl
  8.                 Try
  9.                     ctlTxt.MaxLength = pDT.Columns(ctlTxt.DataBindings("Text").BindingMemberInfo.BindingField.ToString()).MaxLength
  10.                 Catch ex As Exception
  11.                     'no big deal
  12.                 End Try
  13.  
  14.             End If
  15.         Next
  16.  
  17.     End Sub
  18.  
  19.  
Just supply the form and the datatable
Jul 26 '07 #1
0 1037

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Lovely Dola | last post by:
I have set the MaxLength property of a textbox in a form to 5 at design time. When I change the MaxLength back to 0 during run-time under some condition (for example, after clicking a command...
2
by: SC | last post by:
I have two identical textboxes and two identical images that go are next to them. Only the names are different. I have onBlur trigger a function to make sure the boxes were not left empty. If a...
4
by: Rodrigo DeJuana | last post by:
Howdy, I'm new to this .net stuff and really have little to no training. Im trying to create a new page for a web form, so i have been pretty much jsut coping code. I having some issue with...
14
by: Adam Clauss | last post by:
I've an application which is using a multiline textbox to log the status of a fairly long procedure. "Updates" are made to the status by calling textbox.AppendText. As my task is fairly lengthy,...
1
by: mg | last post by:
I have a MultiLine TextBox (WebForm - C#) with the MaxLength property = 1000 but am able to type in an unlimited number of characters. Is there a way to limit the number of characters that can be...
4
by: hardcoded | last post by:
I have a textbox with TextMode set to MultiLine. I also have the MaxLength set to 255. This maxlength value seems to get ignored as the user can enter unlimited characters. Does the multiline...
3
by: RSB | last post by:
Hi Everyone, I have this TextBox with the TextMode="MultiLine". so now it does not validate the text in the TextBox for the MaxLength SO i have decided to execute a CustomValidator for this...
3
by: h | last post by:
Hi, I have set my textbox's maxlength property to 1 , however it allow more than one word. Is there any settings that I am missing ? Thanks in advance Hardik Shah
0
by: sjickells | last post by:
Hi I am having a problem using asp:TextBox's in a transparent table. I have a background image on the page and a table in the middle of the page. I have set the background colour of the table...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.