Solved

How to autocorrect a wrong input on a cell of DBGrid?

Posted on 2004-10-01
9
348 Views
Last Modified: 2010-04-05
I want my DBGrid is able to autocorrect a wrong input on a cell
when the focus moves to a new cell. Currently, I've tried the
following techniques but it fails:

(1) Handling OnColExit event and do the correction when it's     necessary. The problem is, OnColExit event only occurs if     user move the focus to a new different column. This event     doesn't occur if user move the focus to a different row at     the same column.

(2) Handling TField.OnValidate event and do the correction when it's necessary. The problem is, it will continuously execute the TField.Onvalidate event because any writing to a cell will also execute the TField.OnValidate event.

Anybody here could tell me how the best way to do that?

Thank's in advance
0
Comment
Question by:setankabir
  • 3
  • 2
9 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 12200396
? what do you autocorrect ?

maybe you can use the onBeforePost-event of the Dataset

meikl ;-)
0
 

Author Comment

by:setankabir
ID: 12206354
OnBeforePost event doesn't occur when user moves the focus to a different column at the current row.
0
 
LVL 6

Expert Comment

by:Amir Azhdari
ID: 12206525
setankabir ,
try with DBGrid1DrawDataCell event
it mean :


procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
  Field: TField; State: TGridDrawState);
begin
adotable1.edit;
if field.asstring='HLEP' then
   field.Asstring:='HELP';

end;
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 6

Accepted Solution

by:
Amir Azhdari earned 250 total points
ID: 12206652
and better code :

procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
  Field: TField; State: TGridDrawState);
begin
adotable1.edit;
if  (field.FieldNo=0) { just do if it's the first column} AND (field.DataType=ftstring)   then
begin
if field.asstring='HLEP' then
   field.Asstring:='HELP'
  else
if field.asstring='TSET' then
   field.Asstring:='TEST'
end
else
if field.DataType=ftinteger then
begin
if field.asinteger=12 then
   field.Asinteger:=121
  else
if field.asinteger=13 then
   field.Asinteger:=131;
end;

0
 

Author Comment

by:setankabir
ID: 12210685
How do I know the index and value of the cell just before the focus moved?

DBGrid.SelectedField.AsString in the OnDrawDataCell event only give me value of the cell at current focus (after the focus moved). I've also tried to get the index of previous selected cell  by updating my own variable which is set to the current index of selected cell on the OnEnter and OnColEnter event and then use the variable on the OnDrawDataCell event, but the result was just the same with DBGrid.SelectedField.AsString statement. What should I do now?
0
 
LVL 6

Expert Comment

by:Amir Azhdari
ID: 12211001
in that case you should work with one of these events:  ADOTable1BeforePost   OR   ADOTable1BeforeScroll

it mean :

procedure TForm1.ADOTable1BeforePost(DataSet: TDataSet);
begin
showmessage(inttostr(dbgrid1.DataSource.DataSet.RecNo));
showmessage(dbgrid1.DataSource.DataSet.Fields[0].asstring);
end;


OR :

procedure TForm1.ADOTable1BeforeScroll(DataSet: TDataSet);
begin
showmessage(inttostr(dbgrid1.DataSource.DataSet.RecNo));
showmessage(dbgrid1.DataSource.DataSet.Fields[0].asstring);
end;

0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Master Detail with TADODataset 4 97
code issue 8 85
Delphi : could not find program, '...exe' 2 117
oracle global variables 4 52
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

760 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

20 Experts available now in Live!

Get 1:1 Help Now