?
Solved

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

Posted on 2004-10-01
9
Medium Priority
?
362 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
[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
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
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 6

Accepted Solution

by:
Amir Azhdari earned 1000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

777 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