Solved

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

Posted on 2004-10-01
9
351 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

911 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

21 Experts available now in Live!

Get 1:1 Help Now