[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2004-10-01
9
Medium Priority
?
363 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
Independent Software Vendors: 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

Independent Software Vendors: 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!

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

656 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