?
Solved

dbgrid

Posted on 2000-08-23
6
Medium Priority
?
447 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 300 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…
Suggested Courses

850 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