Solved

dbgrid

Posted on 2000-08-23
6
409 Views
Last Modified: 2012-06-27
how i can make a validation by field_level within the dbgrid , on another way how i can check a text that i input it in a column if it is correct or not and if it's not i want to prevent the curssor from the moving to another cell(by press the return key) untel input a correct data
0
Comment
Question by:nadernabil
  • 3
  • 2
6 Comments
 
LVL 1

Expert Comment

by:marcgale
ID: 4044467
I would check that the text is valid and then return the cursor to the cell (and blank it out, if necessary) if the check determined the text to be invalid.
0
 
LVL 2

Expert Comment

by:Sidneym
ID: 4047711
Check out the event:

DBGrid1_BeforeColUpdate

In this event , you can validate the new value, track the old value, and cancell the update if your validation requires it !!

hope this would help!!
0
 

Accepted Solution

by:
gkakas earned 100 total points
ID: 4049191
The event
BeforeColUpdate(ByVal ColIndex As Integer, OldValue As Variant, Cancel As Integer)

is triggered just before data is accepted by the grid and then the focus moves to somewhere else.

The parameter ColIndex is the id of the column in the Columns collection and indicates the field being edited.

Parameter OldValue is obviously the previous value of the cell and Cancel is a boolean variable that can be set to true in order to prevent the grid from accepting the value entered by the user and moving to next cell or somewhere else.

Now this is how you get the value that the user entered:

Dim Text as string

Text = dbgrid1.Columns(ColIndex).Text


(If you need info about the current row you can use the rowbookmark dbgrid1.RowBookmark(dbgrid1.Row) in any way you like.)

Finaly you have to do your validation:
select case colindex
   case constMyValidationColumnID
        if not text like sMypattern then cancel=true
   case else
end select
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 2

Expert Comment

by:Sidneym
ID: 4049277
Hey gkakas ,

I thought that was what i just suggested.
0
 

Expert Comment

by:gkakas
ID: 4049406
Dear Sidneym,

Sorry if it is so, I am new here and saw no info about getting current value and I think it is not obvious that you have to read the grid text to get it, although it is necessary for the validation of data.

But if you still feel I should withdraw the answer send an email to gkakas@otenet.gr  and I will do it immediatelly.

Yours sincerelly George Kakaletris
0
 
LVL 2

Expert Comment

by:Sidneym
ID: 4061841
gkakas ,

no need , its ok ..after all the goal is to give advice to those who need it.

Cheers!
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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

895 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

12 Experts available now in Live!

Get 1:1 Help Now