Solved

dbgrid

Posted on 2000-08-23
6
404 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

746 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