Solved

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

Posted on 2004-10-01
9
352 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

810 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