Solved

DBGrid control=set maxlength.

Posted on 1998-10-01
7
453 Views
Last Modified: 2013-12-25
Is there a way to set the maxlength of a field in a data grid contol?
0
Comment
Question by:RUSTY
7 Comments
 
LVL 1

Expert Comment

by:abhinavm
ID: 1496576
No there is no direct way to set maxlength of a field. but you can do it by writing some code in keypress event or beforeupdate event, which will check the length of text and if it is more than maximum length you can prompt to user or whatever you want.
0
 

Author Comment

by:RUSTY
ID: 1496577
I've been trying to write some code to do this, but cannot get it to read the len of the field in the data grid column.  Can you post a snippet of code that will do this.  Thanks.
0
 

Author Comment

by:RUSTY
ID: 1496578
Adjusted points to 20
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Expert Comment

by:trkcorp
ID: 1496579
Rusty,
  True DBGrid Pro 5.0 by APEX (the upgrade to DBGrid) allows you to do this very simply.  It has a DataWidth property that you can set on a Column object.  
Ex: TDBGrid1.Columns(1).DataWidth = 255
I have used it ALOT. It prevents users from keying in data that is too long to fit in the field which as I'm sure you're aware causes an error.  I know this is probably not what you want to hear but I thought you might like to know... True DBGrid really is worth buying...
0
 
LVL 3

Accepted Solution

by:
TheAnswerMan earned 20 total points
ID: 1496580
I assume you dont have TrueGrid Pro5..
That IS a pretty badass Grid Control, Its got some cool unbound grid features too.

'Flop this Code in
Private Sub Grid1_KeyPress(KeyAscii As Integer)
 if len(Grid1) > 10 then Keyascii = 0
End Sub

'this will keep you from entering more than 10 characters per field
0
 
LVL 3

Expert Comment

by:TheAnswerMan
ID: 1496581
you could try this too.. if you know what size for each column is

Private Sub Grid1_KeyPress(KeyAscii As Integer)
 Select Case Grid1.col
 case 0
  if len(Grid1) > 1 then Keyascii = 0
 case 1
  if len(Grid1) > 2 then Keyascii = 0
 case 2
  if len(Grid1) > 3 then Keyascii = 0
 end select
End Sub

'this will allow one character in the first
2 in the second..
and three in the third
0
 

Author Comment

by:RUSTY
ID: 1496582
Ah.  Perfect.  Danke.  Aloha.  Tanx.  "A+"
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now