Solved

dbgrid

Posted on 2000-08-23
6
433 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

691 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